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_
The following using count() and explode(), will echo:
The number 1 in this line will counted and it contains the following count 8
PHP:
Edit:
Sidenote:
The regex can be modified to accept other characters that are not included in the standard set.
";
echo "There are ";
echo $count = count(explode(" ", $text));
echo " words in this line, this includes the number(s).";
echo "
";
echo "It will not count punctuations.";
?>