English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP ctype_xdigit() Function Usage and Example

PHP Ctype Function Manual

The ctype_xdigit() function checks if the string contains only hexadecimal characters .

Syntax

ctype_xdigit( $text );

Definition and Usage

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

Parameter

Serial NumberParameters and Description
1

text (required)

The string being tested.

Return value

If each character in the text is a hexadecimal 'digit' (i.e., a decimal digit or [-Fa-If any character in the string is not a hexadecimal 'digit' (i.e., a decimal digit or [

Online Example

<?php
   \$strings = array('ABCDEF', 'SAI!@#$', 'ab12bc99','FF10BC99', 'DDDD', 'ffff');
   
   foreach (\$strings as \$test) {
      if (ctype_xdigit(\$test)) {
         echo "\$test composed of hexadecimal digits.\n";
      }else {
         echo "\$test contains non-hexadecimal numbers.\n";
      }
   }
?>
Test and see‹/›

Output result:

ABCDEF composed of hexadecimal digits.
SAI!@#$ contains non-hexadecimal numbers.
ab12bc99 composed of hexadecimal digits.
FF10BC99 composed of hexadecimal digits.
DDDD composed of hexadecimal digits.
ffff composed of hexadecimal digits.

   PHP Ctype Function Manual