Getting count of each word in a String

by guruprasad 2014-04-03 10:48:34

To find the number of occurence of each word in a string using php:

used function:

str_word_count(strip_tags(str_to_use));

Example:

$testingtext="This is a sample text which explains this";


print_r(array_count_values(str_word_count(strip_tags(strtolower($testingtext)), 1)));


Output for the above example will be


Array
(
[this] => 2
[is] => 1
[a] => 1
[sample] => 1
[count] => 1
[text] => 1
[which] => 1
[explains] => 1

)
643
like
0
dislike
0
mail
flag

You must LOGIN to add comments