PHP Condition to check space is available or not between two or more words


Using below code we can get that space is available or not btween two or more words.

$str = 'Hello World!';
if ($str == trim($str) && strpos($str, ' ') !== false) {
    echo 'has spaces, but not at beginning or end';
}
else{
 echo 'There are no any space in sentence';
}

Previous
Next Post »