• PHP Video Tutorials

PHP - Function ctype_digit()



Syntax

ctype_digit ( $text );

Definition and Usage

It 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

It 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 $test) {
      if (ctype_digit($test)) {
         echo "$test consists of all digits. \n";
      }else {
         echo "$test 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