这是我想出的代码行:
function Count($text)
{
$WordCount = str_word_count($text);
$TextToArray = explode(" ", $text);
$TextToArray2 = explode(" ", $text);
for($i=0; $i<$WordCount; $i++)
{
$count = substr_count($TextToArray2[$i], $text);
}
echo "Number of {$TextToArray2[$i]} is {$count}";
}
所以,这里会发生的是,用户将输入文本、句子或段落。通过使用 substr_count,我想知道单词在数组中出现的次数。不幸的是,输出并不是我真正需要的。有什么建议么?