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 it can be used to find interesting insights. So I’ve decided to make this piece of code publicly available. Like to see this code in action? Have a look at the Keyword density Checker.
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.
Question or suggestions?
Just let me know… And I’ll see what I can do!!
Hey can you specify under what license you publish your code? We’d like to use part of it in an open source project.
Hey Martin,
No problem, you can use it for your project. And a reference to the original script is appreciated..
Success building something nice!
Thanks, here’s the project: https://github.com/MP2-IT-Solutions/keywordanalyst
It shows the keyword density of articles in the backend of the Contao CMS.
Feel free to use it and contribute to it if you happen to have a need for the module :)
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);
}
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.
Hello,
Thank you for script,
But i can’t work special chars, (é,ı,ç.ö etc)
How i can fix it ?
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 (http://simplehtmldom.sourceforge.net/).
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.