diff --git a/core/components/simplesearch/src/SimpleSearch.php b/core/components/simplesearch/src/SimpleSearch.php index 0e1d98e..50d165e 100644 --- a/core/components/simplesearch/src/SimpleSearch.php +++ b/core/components/simplesearch/src/SimpleSearch.php @@ -453,12 +453,12 @@ public function createExtract(string $text, int $length = 200, string $search = public function addHighlighting(string $string, string $cls = 'simplesearch-highlight', string $tag = 'span'): string { $searchStrings = explode(' ', $this->searchString); + $replacement = '<'.$tag.' class="'.$cls.'">$0'; + $searchParts = []; foreach ($searchStrings as $searchString) { - $quoteValue = preg_quote($searchString, '/'); - $string = preg_replace('/' . $quoteValue . '/i', '<'.$tag.' class="'.$cls.'">$0', $string); + $searchParts[] = '(' . preg_quote($searchString, '/') . ')'; } - - return $string; + return preg_replace('/' . implode('|', $searchParts) . '/i', $replacement, $string); } /**