我需要得到一个加载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