ctype_digit(): to check numeric characters
$input_string : String to be checked. ctype_digit() is a PHP filter function checks if all chars in the $input_string are numeric or not. Any thing other than this if present then it return FALSE.
This is a good function to check data coming from insecure sources like user input data. Before storing or processing such data we can use this function check to match our requirement. Now let us try with some examples.
ctype_digit(37); output is False as it is taken as ASCII 37, which is %
Example 2
Output is here
You can change the value of the variable $var and see the result. Decimal points are not allowed ( False ) in ctype_digit.
For easy understanding here is the form to submit data to above script DEMOOutput of HTML forms.Output of all html forms are in string format. Hence if you enter number 35 in the above text box , it will be considered as a string 35 and hence output is equal to True. But if you check the below code the output will be equal to False as it will be considered as ASCII 35 which is equal to #.
Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
![]() |
▼ Web Forms & handling data in PHP |