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 .

  • And for what purpose can you ask? measure nausea? if so, then there are services. Maybe they provide api. - Vitaly Kustov
  • For example, tags for articles automatically substitute, but then here you also need a black list, plus morphology to attach. - chernomyrdin
  • for automatic substitution of keywords in meta tags only tss: D - Elime
  • and what for it is needed, what search engine is this hawala now? Yandex? no longer has he been friends with this for a long time, he himself identifies the words he needs in the text. - Artem
  • @Shrek, Anyway, it won't be superfluous anyway, if these words are also tagged in the text, I think the profit will be - Elime

2 answers 2

$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

 слова 
  • does not work ( - Elime
  • Yes, there is a small error in the output of foreach which is not quite correctly written - you need to swap $word and $count , and in the condition to set >= 3 - chernomyrdin
  • hmm, thanks, works, it remains only to figure out all this code hold + - Elime
 $words = array_count_values(str_word_count($text, 1)); foreach ($words as $word => $count) { if ($count > 3) { echo "$word "; } } 
  • Wow, cool in PHP with functions. What about str_word_count with utf-8? - chernomyrdin