Re: Find/count different word in a text

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 12:59 PM 4/25/2012, Karl-Arne Gjersøyen wrote:
Hello again.
I am looking for a way to find and count different word in a text..
I am thinking on save the text as array and iterate through the array.
Then I like to register all different words in the text.
For example. If bread is used more than one time, I will not count it.
After the check were I have found single (one) word of every words, I
count it and tell how many different word that is in the text.

Is this difficult to do? Can you give me a hint for were I shall look
on www.php.net for a solution to fix this problem? What function am I
in need of?

I would use a combination of the functions str_word_count and array_count_values.

<?php
$str = "This is a test of word counting and this sentence repeats words a a a a a is is is is";
print_r(array_count_values(str_word_count($str, 1)));
?>

Ken Robinson

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux