How to Count the Total Words of String in PHP, How to do, Top 1o Lists, Hacking, Games, Pictures, Tips and Tricks, PHP, Movies.

How to Count the Total Words of String in PHP

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.

Related posts:

Tags: , , , , ,
© 2012 Ataaso. All rights reserved.
Read » How to Count the Total Words of String in PHP Article, Top Ten List, Wordpress Hack, Programming Tricks, Amazing Pictures