To count words in a php string usually we can use str_word_count but I think not always a good solution
$var =\"Hello world!\"; echo str_
Use count(explode(' ', $var));
count(explode(' ', $var));