Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Bugfix/issue 36 #57

Open
wants to merge 1 commit into
base: modx-3.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/components/simplesearch/src/SimpleSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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</'.$tag.'>';
$searchParts = [];
foreach ($searchStrings as $searchString) {
$quoteValue = preg_quote($searchString, '/');
$string = preg_replace('/' . $quoteValue . '/i', '<'.$tag.' class="'.$cls.'">$0</'.$tag.'>', $string);
$searchParts[] = '(' . preg_quote($searchString, '/') . ')';
}

return $string;
return preg_replace('/' . implode('|', $searchParts) . '/i', $replacement, $string);
}

/**
Expand Down