我有这段代码(在Php 7上运行),它会打印出单词的频率。但是,该功能有效,可能不会打印特殊字符,可能是因为str_word_count()
。
// Random words
$freqData = array();
$keywords = "Başka, Başka, küskün küskün otomobil kaçtı buraya küskün otomobil neden kaçtı
kaçtı buraya, oraya KISMEN @here #there J.J.Johanson hep.
Danny:Where is mom? I don't know! Café est weiß for 2 €uros.
My 2nd nickname is mike18.";
// Set letter count to exclude words like 'and'/'or', etc.
$letterCount = 5;
// Get individual words and build a frequency table
foreach (str_word_count($keywords, 1) as $word) {
// If the word has more than x letters
if (mb_strlen($word, 'UTF-8') >= $letterCount) {
// For each word found in the frequency table, increment its value by one
array_key_exists($word, $freqData) ? $freqData[$word]++ : $freqData[$word] = 0;
}
}
echo $freqData;
我在<meta charset="UTF-8">
部分有<head>
。
我该如何解决这个问题?