Home >Backend Development >PHP Tutorial >A simple way to count the number of words in a string in php, count words in a string in php_PHP tutorial
The example in this article describes how to simply count the number of words in a string in php. Share it with everyone for your reference. The specific implementation method is as follows:
<?php function word_count($sentence){ $array = explode(" ", $sentence); return count($array); } $words = word_count("The is a group of words"); echo $words; ?>
I hope this article will be helpful to everyone’s PHP programming design.