Use str_replace for matching searchwords, thanks to Dietrich Raisin

This commit is contained in:
Garvin Hicking 2007-09-28 07:46:34 +00:00
parent e8a2d18a11
commit e9545daaf9
2 changed files with 5 additions and 1 deletions

View File

@ -3,6 +3,10 @@
Version 1.3 () Version 1.3 ()
------------------------------------------------------------------------ ------------------------------------------------------------------------
* Highlighting searched words in entries now uses str_replace instead
of slower and possibly insecure preg_replace(). Thanks to
Dietrich Raisin!
* New plugin API method "parseTemplate($filename)" to allow a * New plugin API method "parseTemplate($filename)" to allow a
sidebar- or event-plugin to fetch+display a smarty template. sidebar- or event-plugin to fetch+display a smarty template.
(garvinhicking) (garvinhicking)

View File

@ -970,7 +970,7 @@ function serendipity_printEntries($entries, $extended = 0, $preview = false, $sm
$searchterms = explode($searchterms, ' '); $searchterms = explode($searchterms, ' ');
foreach($searchterms as $searchdx => $searchterm) { foreach($searchterms as $searchdx => $searchterm) {
$searchclass = "foundterm foundterm".$searchdx; $searchclass = "foundterm foundterm".$searchdx;
$entry['body'] = preg_replace('/('.$searchterm.')/mi', '<span class="'.$searchclass.'">\1</span>', $entry['body']); $entry['body'] = str_replace($searchterm, '<span class="'.$searchclass.'">' . $searchterm . '</span>', $entry['body']);
} }
} }