Here is my simplest code for counting the words of any sentence CODE function count_words($val) { $val = explode(‘ ‘,$val); $val = count($val); return $val; } This function returns the total words of the sentence. How To Use $sentence = “I Love Ataaso.com”; $total_words = count_words($sentence ); echo $total_words; OUTPUT OUTPUT is 3.
↧