PHP - 确保字符串没有空格
2022-08-30 15:48:53
如何检查PHP字符串是否包含任何空格?我想检查那里是否有空格,然后回显错误消息(如果为真)
if(strlen($username) == whitespace ){
echo "<center>Your username must not contain any whitespace</center>";
如何检查PHP字符串是否包含任何空格?我想检查那里是否有空格,然后回显错误消息(如果为真)
if(strlen($username) == whitespace ){
echo "<center>Your username must not contain any whitespace</center>";
if ( preg_match('/\s/',$username) ) ....
试试这个:
if (count(explode(' ', $username)) > 1) {
// some white spaces are there.
}