PHP | ctype_digit() (Checks for numeric value) Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report A ctype_digit() function in PHP used to check each and every character of text are numeric or not. It returns TRUE if all characters of the string are numeric otherwise return FALSE. Syntax : ctype_digit(string text) Parameter Used: The ctype_digit() function in PHP accepts only one parameter. text : Its mandatory parameter which specifies the tested string. Return Values: It returns TRUE if all characters of the string are numeric otherwise return FALSE. Errors and Exceptions: Gives Expected result when passing string not gives desired output when passing an integer. The function returns true on empty string previous versions of PHP 5.1.0 Examples: Input :789495001 Output : Yes Explanation : All digits, return True Input : 789.0877 Output : No Explanation: String contains floating point, return false. Below programs illustrate the ctype_digit() function. Program: 1 Checking ctype_digit() function for a single string which contains all digits. PHP <?php // PHP program to check given string is // control character $string = '123456789'; // Checking above given string // by using of ctype_digit() function. if ( ctype_digit($string)) { // if true then return Yes echo "Yes\n"; } else { // if False then return No echo "No\n"; } ?> Output: Yes Program: 2 Drive a code ctype_digit() function where input will be array of string which contains special characters, integers, strings. PHP <?php // PHP program to check is given string // contains all digits using ctype_digit $strings = array( 'Geeks-2018', '[email protected]', '10.99999Fe', '12345', 'geeksforgeeks.org' ); // Checking above given strings //by used of ctype_digit() function . foreach ($strings as $testcase) { if (ctype_digit($testcase)) { // if true then return Yes echo "Yes\n"; } else { // if False then return No echo "No\n"; } } ?> Output: No No No Yes No ctype_digit() vs is_int() ctype_digit() is basically for string type and is_int() for integer types. ctype_digit() traverses through all characters and checks if every character is digit or not. For example, PHP <?php // PHP code to demonstrate difference between // ctype_digit() and is_int(). $x = "-123"; if (ctype_digit($x)) echo "Yes\n"; else echo "No\n"; $x = -123; if (is_int($x)) echo "Yes"; else echo "No"; ?> Output: No Yes References :https://www.php.net/manual/en/function.ctype-digit.php Comment More infoAdvertise with us Next Article PHP | is_numeric() Function J jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP | ctype_alpha() (Checks for alphabetic value) A ctype_alpha() function in PHP used to check all characters of a given string are alphabetic or not. If all characters are alphabetic then return True otherwise return False. Syntax: ctype_alpha($text) Parameters Used: $text :- It is a mandatory parameter which specifies the string. Return Value: I 2 min read PHP check if a number is Even or Odd Checking if a number is even or odd involves determining whether the number is divisible by 2. An even number has no remainder when divided by 2, while an odd number has a remainder of 1. This can be done using various methods like modulo or bit manipulation.Examples :Input : 42 Output : Even Explan 3 min read PHP | Sum of digits of a number This is a simple PHP program where we need to calculate the sum of all digits of a number. Examples: Input : 711 Output : 9 Input : 14785 Output : 25 In this program, we will try to accept a number in the form of a string and then iterate through the length of the string. While iterating we will ext 1 min read PHP | is_numeric() Function The is_numeric() function is an inbuilt function in PHP which is used to check whether a variable passed in function as a parameter is a number or a numeric string or not. The function returns a boolean value. Syntax: bool is_numeric ( $var ) Parameters: The function accepts a single parameter which 2 min read PHP mb_decode_numericentity() Function The mb_decode_numericentity() is an inbuilt function in PHP, where the reference for the numeric string in HTML will be decoded into characters. Syntax: mb_decode_numericentity(string $string, array $map, ?string $encoding = null): stringParameters: This function has four parameters: $string: This p 1 min read PHP | Palindrome Check In this article, we will learn how to check whether a number and a string is a palindrome or not in PHP. A number or string is said to be a palindrome if it remains same even after reversing the digits or letters respectively.Examples for Palindrome Number: Input : 1441 Output : Palindrome Explanati 3 min read Like