How to check whether a string has no whitespace in php?
To check whether a string has no whitespace, use the preg_match() in PHP.
1. Code:
<?php
function checkStringHasNoWitespace($string){
if ( preg_match('/\s/',$string) ){
return "The string (".$string.") has the space";
} else {
return "The string (".$string.") has not the space";
}
}
$name="John Smith";
echo checkStringHasNoWitespace($name);
?>
2. Example:
Input:
string: "John Smith"
Output:
The string (John Smith) has the space