You are here

function keyword_rules_density in SEO Compliance Checker 6

Same name and namespace in other branches
  1. 6.2 keyword_rules/keyword_rules.module \keyword_rules_density()

Dervies the densitiy of keywords within the body of the node.

Parameters

object $form_values:

1 string reference to 'keyword_rules_density'
keyword_rules_register_seo_rules in keyword_rules/keyword_rules.module
Implementation of hook_register_seo_rules().

File

keyword_rules/keyword_rules.module, line 65
Implements some keyword based rules for the SEO Checker.

Code

function keyword_rules_density($form_values) {
  $tags = _keyword_rules_extract_tags($form_values);
  if (count($tags) == 0) {
    return 0;
  }
  $body = strip_tags($form_values['body']);
  $words = preg_split('/\\W+/', $body);
  $total = count($words);
  $nr_of_tags = 0;
  foreach ($tags as $tag) {
    $pos = -1;
    while (($pos = seo_checker_wordipos($body, $tag, $pos + 1)) !== FALSE) {
      $nr_of_tags++;
    }
  }
  return 100 * $nr_of_tags / $total;
}