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
What is the difference between print and echo?What is the difference between join and implode in PHP?
How do I make the first letter of a string uppercase?
I have a script that spits data in this format : Title 1.a 2.b 3.c Title 2 1.a 2.b and so on. The code is quite simple. echo $title echo $lines. How can i make a selection and change the display?
how to compare strings in PHP?
