检查字符串是否只是空格? [英] Check if string is just white space?
本文介绍了检查字符串是否只是空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
如果字符串仅包含空格?
Possible Duplicate:
If string only contains spaces?
我不想更改字符串,也不想检查它是否包含空白.我想检查整个字符串是否仅是 空格.最好的方法是什么?
I do not want to change a string nor do I want to check if it contains white space. I want to check if the entire string is ONLY white space. What the best way to do that?
推荐答案
这将是最快的方法:
$str = ' ';
if (ctype_space($str)) {
}
在空字符串上返回false,因为空是不是空格.如果需要包含一个空字符串,则可以添加|| $str == ''
,这仍将比regex或trim更快地执行.
Returns false on empty string because empty is not white-space. If you need to include an empty string, you can add || $str == ''
This will still result in faster execution than regex or trim.
这篇关于检查字符串是否只是空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文