Reply Thread Tools Search this Thread
Old 01-01-2009, 11:56   #1 (permalink)
vip80
Registered User
 
Join Date: Jan 2009
Posts: 1
PHP: Count word Frequency on Text file

Hi,

Could any one help me with this please.. I don't have much time left.
I'm trying to calculate the 8-10 most frequent words in a text file and save them on MySQL database.

could any one direct me how to do that.
so far I've got this code which calculate the frequency for each word and print them out on text file but I need to remove the stop words and save the top 10 on my database.

function word_frequency($text,$filename,$counter) {

$FileName = $counter.'.txt';

$encodeText = file_get_contents ($FileName);

$wordfrequenc = "";
$str = $encodeText;
$word_count = (array_count_values(str_word_count(strtolower($str ),1)));
ksort($word_count);
foreach ($word_count as $key=>$val) {

$wordfrequenc = $wordfrequenc." ".$key ." = ". $val."<br/>";

} //end foreach

$myFile = $counter.'frequency.txt';
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $wordfrequenc);

} //end function

?>

Any suggestions?

Many thanks..
  Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive
vBulletin © 2000-2009 Jelsoft Enterprises Limited.
Search Engine Optimization by vBSEO 3.0.0 RC8