我需要得到一個加載txt文件的最終結果,計算每個單詞已被使用和回聲結果的次數。代碼使用如下。尋找寶貴的建議...PHP讀取文件錯誤
<?php
$text = fopen("words.txt", "r");
$textarray = explode(" ",$text);
foreach($textarray as $numbers)
{
if(isset($str_count[$numbers]))
$str_count[$numbers]++;
else
$str_count[$numbers]=1;
}
foreach($str_count as $words => $numbers)
echo $words.": ".$numbers."<br>";
?>
你的問題是,什麼不起作用? – 2012-01-30 11:04:16
我要做的第一個註釋是你應該爲'preg_split('/ \ s + /',$ text)交換'explode()'''這樣你就可以解釋多個空格,製表符,換行符等。 – DaveRandom 2012-01-30 11:05:14
除了事實上,你沒有使用PHP的內置str_word_count()函數來生成你的單詞和頻率列表,究竟是什麼問題 – 2012-01-30 11:05:31