You are here: Re: [SMARTY] google highlight « Smarty Templates Posts « IT news, forums, messages
Re: [SMARTY] google highlight

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);
}
?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация