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?How do I remove trailing whitespace?
How do you hash the password in this php script: define(sb db user name, admin store); define(sb db password, mypassword);
How can I remove spaces from around a string value?
How do I count how many times each character occurs in a string?
