开发者

php - detect if variable has only spaces or not

I have a variable, and I need to only add it to an array if it contains something other than spaces.

Up until now I had been using $var != ''. That only covers if it's an empty string. I need i开发者_如何转开发t to cover if it has spaces in it.


This will check if a string contains at least one non-whitespace character. Whitespace includes spaces, newlines, tabs, etc.

trim($var) != ''


have you tried empty() ?


trim($var, ' ') != ''
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜