I want to count the words in a specific string , so I can validate it and prevent users to write more than 100 words for example .
I wrote this function but I don\'t
There are n-1 spaces between n objects so there will be 99 spaces between 100 words, so u can choose and average length for a word say for example 10 characters, then multiply by 100(for 100 words) then add 99(spaces) then you can instead make the limitation based on number of characters(1099).
function isValidLength($text){
if(strlen($text) > 1099)
return false;
else return true;
}