Computer >> Computer tutorials >  >> Programming >> PHP

ctype_xdigit() function in PHP


The ctype_xdigit() function in PHP check for character(s) representing a hexadecimal digit. 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.

Syntax

ctype_xdigit(str)

Parameters

  • str − The tested string

Return

The ctype_xdigit() function 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

The following is an example −

<?php
$str = array('ABCD', 'AB768768ff');
foreach ($str as $a) {
   if (ctype_xdigit($a)) {
      echo "$a has all hexadecimal digits. \n";
   } else {
      echo "$a does not have all hexadecimal digits. \n";
   }
}
?>

Output

ABCD has all hexadecimal digits.
AB768768ff has all hexadecimal digits.