(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)
ctype_space — 检测空白字符
如果 text
里面的每个字符都创建某种形式的空白,那么就返回
true
;否则返回 false
。除了空白字符,还包括制表符、垂直制表符、换行符、回车和换页符。当使用空字符串调用时,结果始终为 false
。
示例 #1 ctype_space() 示例
<?php
$strings = array(
'string1' => "\n\r\t",
'string2' => "\narf12",
'string3' => '\n\r\t' // 注意单引号
);
foreach ($strings as $name => $testcase) {
if (ctype_space($testcase)) {
echo "The string '$name' consists of whitespace characters only.\n";
} else {
echo "The string '$name' contains non-whitespace characters.\n";
}
}
?>
以上示例会输出:
The string 'string1' consists of whitespace characters only. The string 'string2' contains non-whitespace characters. The string 'string3' contains non-whitespace characters.