
Johan Barbier - 2006-10-18 07:46:45 -
In reply to message 1 from steve
Hi,
I fail to see a link with my package, but...anyway:
First, you must understand that a GET variable (or a POST one...) is ALWAYS a string.
so :
if (is_int ($_GET['someVar'])) always returns false.
Well, when the GETor POST variable comes from a form, the url or something like that, anyway.
To do what you want to do, you have several options :
- is_numeric (), but it will only check if the variable is numeric, not if it's an integer: 2.25 IS numeric, but IS NOT an integer.
- regular expressions : you can easily check if it's an integer that way, but you have to understand these expressions
- ctype extension, and its function : ctype_digit (). But it must be enabled on your server.
- and a trick using the loose "typing" in PHP : you can cast your GET variable to an integer, and then make a loose comparison (that is, not a strict one : ===) between the returned variable, and your get :
if (intval ($_GET['someVar']) == $_GET['someVar']) {
// you are here if $_GET['someVar'] is an integer.
}
Hope it helps :-)
Cheers,
Johan