开发者

php - detect if variable has only spaces or not

开发者 https://www.devze.com 2023-01-30 03:37 出处:网络
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开发

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

精彩评论

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