Keyword density.

Keyword density is used to determine the number of times a keyword or keyword phrase occurs on a web page / section of content compared to the total number of words found. Many of us are not convinced keyword density is a very important metric for search engines. This is also my personal opinion, but on the other hand I’m convinced it can be used to find interesting insights.

So I’ve decided to make this piece of code publicly available, and in the meantime I’ll think about a useful way to use this functionality (or just a piece of it) as part of another tool.

About the PHP script

  • Extracting content from a web page – Currently the script is able to process a string of words.
  • Stop Words – You can add expand the list of stop words with relevant words for your language, just do a quick search on Google.
  • Function – This code makes use of a function. This isn’t strictly necessary, but for future purposes I think it’s convenient.
  • Generating output – The current code outputs tables using separate foreach loops. You can tinker with it and make it a little more dynamic. But for now I think it’s a good solution to make the code accessible and not over complicated.

To do list (future versions)

  • Extracting content from a page
  • Create a more advanced filter to remove non relevant (reading) characters, so they don’t mess with the output.
  • Your suggestions…!

Current version V1

This isn’t the final version! When i’ve got some spare time I’ll work on the code and add the above features. In the meantime have fun with the code and check this page for future releases and updates.

Keyword density checker PHP script

Download the Multi Keyword density checker PHP script

Function output

Sample of the keywordSorting function. In bold you can find the explanation.

keyword density array

keyword density array

Question or suggestions?

Just let me know… And I’ll see what I can do!!

VN:F [1.9.22_1171]
Rating: 9.3/10 (35 votes cast)
Multi keyword density checker PHP script v1, 9.3 out of 10 based on 35 ratings

7 Responses to “Multi keyword density checker PHP script v1”

  1. Martin M

    Hey can you specify under what license you publish your code? We’d like to use part of it in an open source project.

  2. Kossi Kpetigo

    This is a very good script.. Thank you Jasja!
    My contribution: Since the “str_word_count” does not work for all languages i would change it to “explode”, and it makes everything work for all languages.

    change these lines to this:
    $keywordsArray = str_word_count_utf8($wordStringFiltered);
    $wordCount = count($keywordsArray);

    as this function at the bottom:
    function str_word_count_utf8($str)
    $str = str_replace(array(‘.’, ‘,’, ‘;’), ” , $str);
    $words_to_count = trim( preg_replace(“/\s+/”, ” “, $str) );
    return explode(” “,$words_to_count);

    • Admin

      Hi Kossi, thanks for your input when I’ve got some time I’ll test your suggestion and I’ll add some extra features / improvements.

    • Admin

      Hey Tolga,

      At the moment I don’t have the time to work on this script, but you can have a look at: PHP Simple HTML DOM Parser (

      This is a pretty well documented html parser you can use to extract the text from a web page. I only did some quick testing so far, but I do think it can handle special characters.


Leave a Reply

  • (will not be published)