要检查字符串是否没有空格,请在PHP中使用preg_match()。
语法如下
preg_match('/\s/',$yourVariableName);PHP代码如下
<!DOCTYPE html>
<html>
<body>
<?php
$name="John Smith";
if ( preg_match('/\s/',$name) ){
echo "The name (",$name,") has the space";
} else {
echo "The Name (",$name,") has not the space";
}
?>
</body>
</html>输出结果
这将产生以下输出
The name (John Smith) has the space