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:

   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:


string: "John Smith"


The string (John Smith) has the space