In general, there is such a task:
There is a $ text variable, there is a lot of text in it, you need to track words in this variable that occur 3 or more times .
In general, there is such a task:
There is a $ text variable, there is a lot of text in it, you need to track words in this variable that occur 3 or more times .
$words = array(); foreach (preg_split('/[^a-zа-я-]+/ui', $text) as $word) { if (array_key_exists($word,$words)) { $words[ $word ]++; } else { $words[ $word ] = 1; } } foreach ( $words as $word => $count ) { if ($count >= 3) { echo $word, "\n"; } } UPDATE
With data:
$text = "слова слова сливы слова сливы еще много разных фраз"; On the output we get
слова $word and $count , and in the condition to set >= 3 - chernomyrdin $words = array_count_values(str_word_count($text, 1)); foreach ($words as $word => $count) { if ($count > 3) { echo "$word "; } } str_word_count with utf-8? - chernomyrdinSource: https://ru.stackoverflow.com/questions/65008/
All Articles