Bolt\Helpers\Excerpt::extractLocations PHP Method

extractLocations() private method

Nothing exciting here. The array_unique is required, unless you decide to make the words unique before passing in.
private extractLocations ( array $words, string $fulltext ) : array
$words array
$fulltext string
return array
    private function extractLocations(array $words, $fulltext)
    {
        $locations = [];
        foreach ($words as $word) {
            $wordLen = strlen($word);
            $loc = stripos($fulltext, $word);
            while ($loc !== false) {
                $locations[] = $loc;
                $loc = stripos($fulltext, $word, $loc + $wordLen);
            }
        }
        $locations = array_unique($locations);
        sort($locations);
        return $locations;
    }