• PHP Video Tutorials

PHP - Function ctype_xdigit()



Syntax

ctype_xdigit ( $text );

Definition and Usage

This function checks if all of the characters in the provided string, text, are hexadecimal 'digits'.

Parameters

Sr.No Parameter & Description
1

text(Required)

The tested string.

Return Value

It returns TRUE if every character in text is a hexadecimal 'digit', that is a decimal digit or a character from [A-Fa-f], FALSE otherwise.

Example

Try out following example −

<?php
   $strings = array('ABCDEF', 'SAI!@#$', 'ab12bc99');
   
   foreach ($strings as $test) {
      if (ctype_xdigit($test)) {
         echo "$test consists of all hexadecimal digits. \n";
      }else {
         echo "$test does not have all hexadecimal digits. \n";
      }
   }
?> 

This will produce the following result −

ABCDEF consists of all hexadecimal digits.
SAI!@#$ does not have all hexadecimal digits.
ab12bc99 consists of all hexadecimal digits.
php_function_reference.htm
Advertisements