如果位元組介於 \x00-\x1f 或 \x7f (del) 之間,則返回 true。如果位元組介於 \x20-\x7e 或 \x80-\xff 之間,則返回 false。
(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)
ctype_cntrl — 檢查控制字元
文字
被測試的字串。
備註:
如果提供 -128 到 255 之間(含)的 整數,它會被解釋為單個字元的 ASCII 值(負值會加上 256,以便允許擴展 ASCII 範圍內的字元)。任何其他整數都會被解釋為包含整數十進位數字的字串。
範例 #1 ctype_cntrl() 範例
<?php
$strings = array('string1' => "\n\r\t", 'string2' => 'arf12');
foreach ($strings as $name => $testcase) {
if (ctype_cntrl($testcase)) {
echo "字串 '$name' 全由控制字元組成。\n";
} else {
echo "字串 '$name' 並非全由控制字元組成。\n";
}
}
?>
以上範例將輸出:
The string 'string1' consists of all control characters. The string 'string2' does not consist of all control characters.