Php Programming Code Examples Php > Code Snippets Code Examples Count words in a sentence Count words in a sentence <?php $strText = "This is a test"; $wordcount = count(explode(" ",$strText)); echo "There are $wordcount words in $strText"; ?>