Keywords from String
2 answers
There is no such function (it would be magical if it were), but to start something, you could do the following:
- Split text in space, creating an array of words.
- Remove stop words and unnecessary punctuation marks and symbols (possibly using regular expressions - see
preg_replace
). - Count the number of occurrences of each word in the remaining array, and sort it in order of frequency (therefore the most common word is at the first offset, i.e.
$words[0]
). - Use array_unique to remove duplicates, thus creating an array of unique keywords, ordered by frequency of occurrence.
+7
source to share
Something like this might do the trick:
$thestring = 'the most important, frequently occuring unique terms?';
$arrayofwords = explode(" ", $thestring);
echo print_r($arrayofwords);
You can also replace the comma "," with a space so that you get clean keywords.
$thestring = 'the most important, frequently occuring unique terms?';
$cleaned_string = str_replace(",", "", "$thestring");
$arrayofwords = explode(" ", $cleaned_string);
echo print_r($arrayofwords);
0
source to share