You are here

function seo_checker_wordipos in SEO Compliance Checker 6.2

Same name and namespace in other branches
  1. 6 seo_checker.module \seo_checker_wordipos()

Find position of first occurrence of a case-insensitive WORD

Parameters

array $haystack:

string $needle:

Return value

int

3 calls to seo_checker_wordipos()
keyword_rules_density in keyword_rules/keyword_rules.module
Dervies the densitiy of keywords within the body of the node.
keyword_rules_headings in keyword_rules/keyword_rules.module
keyword_rules_title in keyword_rules/keyword_rules.module
Checks if keywords are used in the node title. If they are used, the resulting score depends on how early the keywords occur in the title. If a keyword is used as the first word in the title, the score will be 100%.

File

./seo_checker.module, line 181

Code

function seo_checker_wordipos($haystack, $needle, $offset = 0) {
  $pos = -1;
  $found = FALSE;
  while ($found === FALSE) {
    $pos = stripos($haystack, $needle, $offset);
    if ($pos === FALSE) {
      return FALSE;
    }

    /* check if the characters before and after the found tag are non-word characters */
    $expanded_string = (isset($haystack[$pos - 1]) ? $haystack[$pos - 1] : ' ') . (isset($haystack[$pos + strlen($needle)]) ? $haystack[$pos + strlen($needle)] : ' ');
    if (preg_match_all('/[\\W_]/', $expanded_string, $null) == 2) {
      $found = TRUE;
    }
    $offset = $pos + 1;
  }
  return $pos;
}