PHP - Function ctype_digit()


Advertisements


Syntax

ctype_digit ( $text );

Definition and Usage

Checks if all of the characters in the provided string, text, are numerical. It checks only 1...9

Parameters

Sr.No Parameter & Description
1

text

Required. The tested string.

Return Value

Returns TRUE if every character in text is a decimal digit, FALSE otherwise.

Example

Try out following example −

<?php
   $strings = array('122.50', '1004', 'foo!#$bar');
   
   foreach ($strings as $testcase) {
      if (ctype_digit($testcase)) {
         echo "$testcase consists of all digits. \n";
      }else {
         echo "$testcase does not have all digits. \n";
      }
   }
?> 

This will produce the following result −

122.50 does not have all digits
1004 consists of all digits
foo!#$bar does not have all digits

php_function_reference.htm

Advertisements