ctype_xdigit
(PHP 4 >= 4.0.4, PHP 5, PHP 7)
ctype_xdigit — 16 進数を表す文字かどうかを調べる
パラメータ
text
調べる文字列。
注意:
-128 から 255 までの int を渡すと、ひとつの文字の ASCII 値とみなします (負の値には 256 を足して、拡張 ASCII の範囲に収まるようにします)。 それ以外の整数値は、10 進数を含む文字列とみなします。
返り値
text
のすべての文字が 16 進の '数字'
つまり 10 進の数字または [A-Fa-f]
だった場合に true
、そうでない場合に 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.