I have this piece of code (running on Php 7) which will print out the frequency of words. The function works, however, special characters are not printed, probably because of 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;
I have <meta charset="UTF-8">
in the <head>
section.
How can I solve this?