Ticket #557: text_transform.diff

File text_transform.diff, 1.0 KB (added by AlphaLaser, 16 years ago)

proposed fix

  • text_transform.inc

    old new  
    259259// Highlight terms in text (most likely used with searches)
    260260
    261261function highlight_terms($text, $terms) {
    262     $search = $terms;
    263     $replace = array();
    264 
    265     foreach ($search as $key => $value) {
    266         $replace[$key] = "<span class=\"highlight\">".$value."</span>";
    267     }
    268     if (substr(phpversion(), 0, 1) > 4) {   // PHP 4.x doesn't support str_ireplace
    269         return str_ireplace($search, $replace, $text);
    270     } else {
    271         return str_replace($search, $replace, $text);
     262    // See example in http://us3.php.net/eregi_replace
     263    foreach ($terms as $term) {
     264      $pattern = '(>[^<]*)('. $term .')';
     265      $replacement = '\\1<span class="highlight">\\2</span>';
     266      $text = eregi_replace($pattern, $replacement, $text);
    272267    }
     268
     269    return $text;
    273270}
    274271
    275272$cvs_version_tracker[]="\$Id: text_transform.inc 15758 2008-08-05 22:43:14Z davea $";  //Generated automatically - do not edit