Notes

Note:

This function expects a string to be useful, so for example passing
in an integer may not return the expected result. However, also note that
HTML forms will result in numeric strings and not integers. See also the
types section of the manual.

Note:

If an integer between -128 and 255 inclusive is provided, it is interpreted as
the ASCII value of a single character (negative values have 256 added in order to allow
characters in the Extended ASCII range). Any other integer is interpreted as a string
containing the decimal digits of the integer.

User Contributed Notes 9 notes

All basic PHP functions which i tried returned unexpected results. I would just like to check whether some variable only contains numbers. For example: when i spread my script to the public i cannot require users to only use numbers as string or as integer. For those situation i wrote my own function which handles all inconveniences of other functions and which is not depending on regular expressions. Some people strongly believe that regular functions slow down your script.

The reason to write this function:1. is_numeric() accepts values like: +0123.45e6 (but you would expect it would not)2. is_int() does not accept HTML form fields (like: 123) because they are treated as strings (like: "123").3. ctype_digit() excepts all numbers to be strings (like: "123") and does not validate real integers (like: 123).4. Probably some functions would parse a boolean (like: true or false) as 0 or 1 and validate it in that manner.