array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.ctype-xdigit.php', 1 => 'ctype_xdigit', ), 'up' => array ( 0 => 'ref.ctype.php', 1 => 'Ctype 函数', ), 'prev' => array ( 0 => 'function.ctype-upper.php', 1 => 'ctype_upper', ), 'next' => array ( 0 => 'book.filter.php', 1 => '过滤器', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/ctype/functions/ctype-xdigit.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)
ctype_xdigit — 检测字符是否只包含十六进制字符
如果 text
中每个字符都是十六进制“数字”,也就是只能包含十进制数字和
[A-Fa-f]
的字符,那么就返回 true
。否则返回 false
。当使用空字符串调用时,结果始终为 false
。
示例 #1 ctype_xdigit() 示例
<?php
$strings = array('AB10BC99', 'AR1012', 'ab12bc99');
foreach ($strings as $testcase) {
if (ctype_xdigit($testcase)) {
echo "The string $testcase consists of all hexadecimal digits.\n";
} else {
echo "The string $testcase does not consist of all hexadecimal digits.\n";
}
}
?>
以上示例会输出:
The string AB10BC99 consists of all hexadecimal digits. The string AR1012 does not consist of all hexadecimal digits. The string ab12bc99 consists of all hexadecimal digits.