Someone has already done this.
The magic you are looking for is a php function called str_word_count () .
In my code example below, if you get a lot of extra words from this, you will need to write a custom description to remove them. In addition, you will want to remove all html tags with words and other characters.
I am using something similar to this to generate keywords (obviously the code is property). In short, we take the provided text, we check the word frequency, and if the words appear in order, we sort them in an array based on priority. Therefore, the most common words will be the first to exit. We do not take into account words that occur only once.
<?php $text = "your text."; //Setup the array for storing word counts $freqData = array(); foreach( str_word_count( $text, 1 ) as $words ){ // For each word found in the frequency table, increment its value by one array_key_exists( $words, $freqData ) ? $freqData[ $words ]++ : $freqData[ $words ] = 1; } $list = ''; arsort($freqData); foreach ($freqData as $word=>$count){ if ($count > 2){ $list .= "$word "; } } if (empty($list)){ $list = "Not enough duplicate words for popularity contest."; } echo $list; ?>
AbsoluteΖ΅ERΓ
source share