{ Lekker Logic }

Technology Solutions

PHP Extract Most Used Words in a String or Paragraph

Here is a neat little PHP function that pulls out the most common words from a string and ranks them based on frequency used.  A preset list of words in an external .txt file provide the “skip word” reference, meaning they are not counted as a common occurrence.  This prevents the, a, and etc from showing up.

To call the function:

The function:


The text file for stop_words.txt is just a list of words and common phrases.  To include the .txt file use this line of PHP somewhere in your page:


If you wanted to show the results in a comma separated list you could use something like the below:


Lekker Logic
Tags: functions, PHP, Programming, Snippet, Web