ctype_graph() 函数做可打印字符串检测,空格除外
ctype_graph ( $text );
检查提供的 text 里面的字符输出都是可见的。
| 序号 | 参数及说明 |
|---|---|
| 1 | text(必需) 要被测试的字符串。 |
如果文本中的每个字符都是可打印的,并且实际上创建了可见的输出(没有空格),则返回TRUE,否则返回FALSE。
<?php
$strings = array('string1' => "asdf\n\r\t", 'string2' => 'arf12', 'string3' => 'LKA#@%.54');
foreach ($strings as $test) {
if (ctype_graph($test)) {
echo "$test 由可见可打印字符组成 \n";
}else {
echo "$test 含有不可见字符。 \n";
}
}
?>测试看看‹/›输出结果:
asdf 含有不可见字符。 arf12 由可见可打印字符组成 LKA#@%.54 由可见可打印字符组成