문자열에 공백이 없는지 확인하려면 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