Home > Code Snippets > Count number of words in a text string
Count number of words in a text string
Description
This will count through the sentences in a section of text and show how many words are contained within it.
The code
<?php
$text = "This is some text.";
$count = count(explode(" ", $text));
echo "$text contains $count words";
?>
Get the code
Download the file to your computer: Click here to get the file
