S4C Posted July 17, 2006 Share Posted July 17, 2006 Hmm how to be sure that my $_GET['page'] is really integer..?Thanks Link to comment https://forums.phpfreaks.com/topic/14842-_get-variables/ Share on other sites More sharing options...
Joe Haley Posted July 17, 2006 Share Posted July 17, 2006 http://ca3.php.net/manual/en/function.is-int.phpis_int is your friend.Edit:http://ca3.php.net/manual/en/function.is-numeric.phpis_numericuse is_numeric if the value you wish to test is of a string data type. Link to comment https://forums.phpfreaks.com/topic/14842-_get-variables/#findComment-59312 Share on other sites More sharing options...
trq Posted July 17, 2006 Share Posted July 17, 2006 Anything sent through $_GET is technically a string, but you could try to force it into being an integer by using typecasting. eg;[code=php:0]if (isset($_GET['page'])) { $page = (int) $_GET['page'];}[/code]Or you might just check it using [url=http://php.net/is_numeric[/url](). Link to comment https://forums.phpfreaks.com/topic/14842-_get-variables/#findComment-59315 Share on other sites More sharing options...
Prismatic Posted July 17, 2006 Share Posted July 17, 2006 The method above will turn a string of text sent via the $_GET into 0, FYI Link to comment https://forums.phpfreaks.com/topic/14842-_get-variables/#findComment-59317 Share on other sites More sharing options...
S4C Posted July 17, 2006 Author Share Posted July 17, 2006 Thanks a lot guys. ;) Link to comment https://forums.phpfreaks.com/topic/14842-_get-variables/#findComment-59318 Share on other sites More sharing options...
Orio Posted July 17, 2006 Share Posted July 17, 2006 is_int checks only if the variable is an integer.But if the number is being transfered using GET, POST etc', the variable will be a [b]string[/b] of number/s.So you need to use [url=http://www.php.net/manual/en/function.is-numeric.php]is_numeric()[/url].Orio. Link to comment https://forums.phpfreaks.com/topic/14842-_get-variables/#findComment-59319 Share on other sites More sharing options...
ShogunWarrior Posted July 17, 2006 Share Posted July 17, 2006 You can use [b]is_numeric[/b], convert to [b]intval[/b] and [b]is_int[/b] after each other to check. Link to comment https://forums.phpfreaks.com/topic/14842-_get-variables/#findComment-59321 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.