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
Using substr_count to Count the number of any substring occurrences. for finding number of words set $needle to ' '. int substr_count ( string $haystack , string $needle)
$text = 'This is a test';
echo substr_count($text, 'is'); // 2
echo substr_count($text, ' ');// return number of occurance of words