Most frequently words in a text
| From: | buzon at alejandro dot ceballos dot info | Date: | Thu, 17 Jan 2008 18:39:59 +0000 |
| Subject: | Most frequently words in a text | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-44528@lists.php.net to get a copy of this message | ||
Hello everybody,
I am creating an algorithm to identify the most frequently words on different sentences, using the following code:
// store in $arr_frequencyids all different words
for($i=0; $i<count($arr_phrase); $arr_phrase)
{ array_push($arr_frequencyids,explode(" ",$arr_phrase[$i])); }
// use a hash using words as keys, and increment as frequency
for ($i=0; $i<count($arr_frequencywords); $i++)
{
$str_thisword = $arr_frequencywords[$i];
$hash_frequencywords[$str_thisword]++;
}
// descendent sort based on values
arsort($hash_frequencywords);
// store in $arr_20mostusedwords the 20 most frequent words
$arr_20mostusedwords = array_slice(array_keys($hash_frequencywords,0,20));
But... is not working. It is not counting the ocurrences. It stores as a long string, even I used explode or trying a direct array addition (arr1 += arr2).
Warning: Wrong parameter count for array_keys() in /home/mipyme/public_html/jpanel/index.php on line 204
Warning: Wrong parameter count for array_slice() in /home/mipyme/public_html/jpanel/index.php on line 204
Warning: array_slice() [function.array-slice]: The first argument should be an array in /home/mipyme/public_html/jpanel/index.php on line 205
Could you give me some direction? (the information comes from a DB, but for simplifying process I asume an array instead a while DB fetch row)
Thank you,
Alejandro