PHP code to exact keywords from text.

PHP code to find out keywords out of text.
There is very simple way to find out keywords out of text and you can do it without having NPL knowledge. Here are following steps…
1. Read text and put in variable.
2. Find words out of text by using regx.
3. Exclude banned or known words if you want.
4. Find frequency of words.

Find words.

$words = array();
$excludeWords = array();
preg_match_all ('/(\w+)/i', $text, $ words);
$words = $this->words ['0'];
$words = array_diff($words,$excludeWords);

Find Frequency.

$words = array_count_values ($words);
arsort ($words);

Get words of more than x frequency.

$a = (int) $a;
$tmp=array();
foreach ($words as $key => $value) {
if ($value >= $a){
		$tmp[$key] = $value;
}
else {
		break;
}
}
return $tmp;

Categories: PHP