How do I count the number of words in my text?
There are a few ways of doing this, a simple way would be to explode the string into an array on the space character, and then see how many entries there are in the array, corresponding to words separated by spaces.
Here's a snippet of code to do just this for you which should serve your needs:
<?php
$text = "I wrote a really long piece of text but I got bored after a little while but this should still give you an example of what this does and how it works";
$words = explode(" ", $text);
$wordcount = count($words);
echo "It seems to me that there are $wordcount words in this snippet of text";
?>
Comment on this Question and Answer >>>
ASK A QUESTION
More strings PHP Questions
How do I make the first letter of a string uppercase?How do I escape a string with slashes?
How do I find the position of a letter in a string in PHP?
how to compare strings in PHP?
How do I remove trailing whitespace from a string?
