PHP - Function ctype_xdigit()


Advertisements


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

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('AB10BC99', 'AR1012', 'ab12bc99');
   
   foreach ($strings as $testcase) {
      if (ctype_xdigit($testcase)) {
         echo "$testcase consists of all hexadecimal digits. \n";
      }else {
         echo "$testcase does not have all hexadecimal digits. \n";
      }
   }
?> 

This will produce the following result −

AB10BC99 consists of all hexadecimal digits.
AR1012 does not have all hexadecimal digits.
ab12bc99 consists of all hexadecimal digits.

php_function_reference.htm