a better example of counting the amount of words in a string

a better example of counting the amount of words in a string

more practical example of counting words in a string.

<?php
$message = "this will have some text filtered out and will not display because it has more than 10 words";
//$message = "this sentence is OK";
$result = str_word_count($message);
if($result > 10)
{
echo "sorry that sentence contains too many words " . $result . " to be exact";
}
else
{
echo $message;
}
?>