English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The ctype_xdigit() function checks if the string contains only hexadecimal characters .
ctype_xdigit( $text );
This function checks if all characters in the provided string are hexadecimal 'digits'.
Serial Number | Parameters and Description |
---|---|
1 | text (required) The string being tested. |
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 [
<?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.