/    Sign up×
Community /Pin to ProfileBookmark

Should I is_int() or is_numeric() The Numbers ?

Folks,

Tell me, should I quote the number or not ?
The following php code is a pagination section like the bottom part of google SERP. The code builds the page numbers at the bottom of the SERP. Like: (Page 12345678910).

[code]
<?php
//$_GET PARAMS:
$search = ‘keyword’;
$tbl = ‘links’;
$col = ‘keyword’;
$max = ‘100’; //Should I quote this to turn it into NUMERIC or should I not quote it to turn it into INT ?
$page = ‘1’; //Should I quote this to turn it into NUMERIC or should I not quote it to turn it into INT ?

if(is_numeric($max))
{
echo “Numeric”;
}

if(is_int($page))
{
echo “Int”;
}

$selfpage = basename(__FILE__,”); //Echoes: url_encode_Template.php. Does not fetch the url $_GET params.
$path = rawurlencode($selfpage);
$query_string = ‘?search=’ .urlencode($search) .’&tbl=’ .urlencode($tbl) .’&col=’ .urlencode($col) .’&max=’ .intval($max) .’&page=’ .intval($page);
$url = $path .htmlentities($query_string); //$url value contains the Full URL With $_GET params: https://localhost/Templates/url_encode_Template.php?search=keyword&tbl=links&col=keyword&max=100&page=1
echo ‘<a href=’ .'”‘ .$url .'”‘ .’>Next</a>’; echo ‘<br>’;
?>
[/code]

**Note these comments:
$max = ‘100’; //Shall I quote this INT/NUMERIC or not ?
$page = ‘1’; //Shall I quote this INT/NUMERIC or not ?**

**Remember:
$max is the total links per SERP.
$page is the SERP number.**

Usually, do you have these numbers $max, $page as INT or NUMERIC ?

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@sibertJun 18.2021 — > @developer_web#1633100 $max = '100'; //Shall I quote this INT/NUMERIC or not ?

The short answer is it depends.

Using SQL you do not need to quote, but I have quotation marked figures by mistake and the char variable converts to numbers automatically. But not the other way around.

But using JSON object, I think you should quote. As JSON is text.


Do you have these numbers $max, $page as INT or NUMERIC
[/quote]


I use INT or BIGINT.
Copy linkTweet thisAlerts:
@NogDogJun 18.2021 — If the intent is to use it as a number, then do _not_ quote it. If the intent is to only use it as a string, then quote it.

While PHP is a loosely typed language, there are still benefits to being explicit in your typing, including improving readability and thus maintainability, and avoiding bugs caused by code that does require specific types.
Copy linkTweet thisAlerts:
@developer_webauthorJun 20.2021 — @NogDog#1633108

In other words I should INT it **(is_int())** and not NUMERIC it **(is_numeric())**.

Thanks!
Copy linkTweet thisAlerts:
@developer_webauthorJun 20.2021 — @sibert#1633102

No. No. About the BIGINT. I wasn't talking about mysql. Was talking about php.

Should I INT it (is_int()) and not NUMERIC it (is_numeric()) ? That was the question. Anyway, got the answer from NogDog that I should INT it.

Thanks for responding.
Copy linkTweet thisAlerts:
@NogDogJun 20.2021 — > @developer_web#1633164 In other words I should INT it (is_int()) and not NUMERIC it (is_numeric()).

Completely depends on what you are doing. E.g.: _all_ values submitted via GET or POST will be string types, so is_int() of any of them will always be false, even if they _look_ like integers.
Copy linkTweet thisAlerts:
@raymeekJun 25.2021 — Hey! Nice to be here. I just developed an amazing mobile app that is really good for student. Check it out and let me know what you fee. Open to feedbacks

https://bit.ly/3gYcllS
Copy linkTweet thisAlerts:
@developer_webauthorJul 18.2021 — @NogDog#1633175

So, I should be checking with is_numeric() then ?

Why do I keep forgetting $_POST and $_GET values are always string ? Can your dog, that I see in the profile, fetch me some "forget me not" flowers for a sniff ? First get it to sniff out the ones that got strong scent. The stronger the scent, the greater would be my memory. Got to rid this mild amnesia or I'll drive you folks crazy with the same answers getting repeated to me over and over again.

Cheers!
Copy linkTweet thisAlerts:
@developer_webauthorJul 23.2021 — @NogDog#1633175

>>all values submitted via GET or POST will be string types, so is_int() of any of them will always be false, even if they look like integers.<<



What if I dump the $_GET number value to a $var and then check if that is a string or not is_str() ? WOuld that make any difference or the value will still be counted as a string too here ?

Copy linkTweet thisAlerts:
@NogDogJul 23.2021 — > @developer_web#1634625 WOuld that make any difference

No. It's already a variable. Copying it into another variable does not change its type.
×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...