function relevanssi_extract_locations($words, $fulltext) { $locations = array(); foreach ($words as $word) { $wordlen = relevanssi_strlen($word); $loc = relevanssi_stripos($fulltext, $word); while ($loc !== FALSE) { $locations[] = $loc; $loc = relevanssi_stripos($fulltext, $word, $loc + $wordlen); } } $locations = array_unique($locations); sort($locations); return $locations; }
function relevanssi_stripos($content, $term, $offset = 0) { if ($offset > relevanssi_strlen($content)) { return false; } if (function_exists('mb_stripos')) { $pos = "" == $content ? false : mb_stripos($content, $term, $offset); } else { if (function_exists('mb_strpos') && function_exists('mb_strtoupper') && function_exists('mb_substr')) { $pos = mb_strpos(mb_strtoupper($content), mb_strtoupper($term), $offset); } else { $pos = strpos(strtoupper($content), strtoupper($term), $offset); } } return $pos; }