PHP中的ctype_space()函数检查空格字符。如果文本中的每个字符都产生某种空白,则返回TRUE,否则返回FALSE。除空白字符外,还包括制表符,垂直制表符,换行符,回车符和换页符。
ctype_space(str)
str-测试的字符串
如果文本中的每个字符都创建某种空白,则ctype_space()函数返回TRUE,否则返回FALSE。除空白字符外,还包括制表符,垂直制表符,换行符,回车符和换页符。
以下是一个例子-
<?php $arr = array(' ', '\test123' ); foreach ($arr as $demo) { if (ctype_space($demo)) { echo "$demo consists of all whitespace characters. \n"; } else { echo "$demo does not have all whitespace characters. \n"; } } ?>
输出结果
consists of all whitespace characters. \test123 does not have all whitespace characters.
<?php $str = " "; if (ctype_space($str)) echo "Whitespace!! \n"; else echo "No Whitespace character! \n"; ?>
输出结果
Whitespace!!