View Single Post
Old 08-30-2005, 03:28 AM   #5 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 734
DJMaze is on a distinguished road
Quote:
Originally Posted by sde
3. when comparing a string to an integer, the string evaluates to zero before it is compared. this means: 'abcdefg' == 0. You can probably imagine the problems it may cause if you might be expecting a 0 as valid input to something that is checking on a string and the zero has not been cast to a string ahead of time.
To avoid this you could try to use is_numeric(), is_int() or empty().
The issue with empty() is that it returns TRUE on: NULL, FALSE, '', 0 and array().
is_int() checks if the value is a integer instead of a string ('abcdefg' === 0 <= triple =)
is_numeric('3e00') will return true as this function supports e-notation.

So maybe just a regex would be best ereg('^[0-9]+$', 'abcdefg')
DJMaze is online now   Reply With Quote