One small caveat I failed to mention earlier: while ctype_digit will work fine for parsing the superglobals, if you are instead parsing an unknown variable that might be an actual integer, a string containing an integer, or a non-integer string, you'll need to first cast it to a string before you apply ctype_digit, as that function returns false if you pass it an actual integer. It's an easy "feature" to forget, and as I did exactly that myself a few minutes ago I thought I'd mention it to potentially save you some time in the future.

$string = '42';
$int = 42;
var_dump(ctype_digit($string), ctype_digit((string) $int), ctype_digit ($int));


$page_index = ctype_digit($_GET['page']) ? $_GET['page'] : $default_page;

Thanks Dann,
I will start using that from now on.  Easy to read, works with 0.
_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php

Reply via email to