How to Calculate Keyword Density of a Web Page

hi!!! guys,

I got a pblm in calcualting Keyword Density.
First thing is I want to know is for which terms Keyword density is calculated.
Whether to take the terms from Title Tag or from different means.

What is the Formula for calculating the same.
i guess this is the formula
Keyword Density is the ratio of a keyword or keyphrase to the total words (depth) on a page.

waiting for the suggestions.....

kiransnaikAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lozlozCommented:
hi,

firstly, if you're loading in an html file, i suppose the best thing to do would be to strip the tags out so you're just left with content, which should be the title and the body.. this should work unless there's some javascript which might be left in, you'll need to test that though. you can use fopen and fread to read in the file into a variable then use $words_to_count = strip_tags($words_to_count);. actually i found this function in the manual which i changed slightly:

$words_to_count = strip_tags($body);
$pattern = "/[^(\w|\d|\'|\"|\.|\!|\?|;|,|\\|\/|\-\-|:|\&|@)]+/";
$words_to_count = preg_replace ($pattern, " ", $words_to_count);
$words_to_count = trim($words_to_count);
$words = explode(" ",$words_to_count);
$total_words = count($words);

then you have the words in $words and the number in $total_words. so you just loop through checking for equivalance to your keywords (if they're stored as an array in $keywords):

$numkeys = 0;
for($x = 0; $x < $total_words; $x++) {
  foreach($keywords as $key => $value) {
    if($keywords[$key] == $words[$x]) {
      $numkeys++;
    }
  }
}
$density = $numkeys / $total_words; # fraction of keywords in all words
$density = $density * 100; # percentage of words in string that are any of the keywords

tell me how you get on

loz
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.