Example 1 — Count Words
The simplest use: how many words are in this sentence?
<?php
$text = "The quick brown fox";
echo str_word_count($text), PHP_EOL; How It Works
- Create a sentence. Words are separated by spaces.
- Call the function. With the default format of
0it returns a count. - Get an integer. The result is
4. - Print it. Use
echoto display the number.

