|
Posted by pete M on 04/18/05 16:41
Thanks to messju here is the modified modifier ;-)))))
<?php
function smarty_modifier_highlight ($text, $search)
{
// Init vars
static $_search_phrases;
// Load saved terms if they have already been parsed.
if (!$_terms = (array)$_search_phrases[$search]) {
// pull out quoted strings
preg_match_all( '/"(.*?)"/', $search, $_quotes);
// split on whitespace
$_terms = array_merge((array)$_quotes[1], explode(' ',
preg_replace( '/".*?"/', ' ', $search )));
$_search_phrases[$search] = $_terms;
}
// Loop through each term and highlight
foreach (array_unique($_terms) as $val) {
// Strip any stray non-matched double quotes and check for
empty string
if (!$val = trim(str_replace('"', '', $val))) continue;
if (preg_match_all('!' . preg_quote($val, '!') . '!i',
$text, $matches, PREG_PATTERN_ORDER)) {
foreach ($matches[0] as $match) {
$trans[$match] = "<span
class='google_highlight'>$match</span>";
}
}
}
return strtr($text, $trans);
}
?>
[Back to original message]
|