Changeset 409


Ignore:
Timestamp:
Apr 1, 2004, 12:25:31 AM (20 years ago)
Author:
z0rglub
Message:

bug 23 : search case insensitive BUT highlightning case sensitive

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions.inc.php

    r405 r409  
    279279}
    280280
    281 // - add_style replaces the
    282 //         $search  into <span style="$style">$search</span>
    283 // in the given $string.
    284 // - The function does not replace characters in HTML tags
     281/**
     282 * replaces the $search into <span style="$style">$search</span> in the
     283 * given $string.
     284 *
     285 * case insensitive replacements, does not replace characters in HTML tags
     286 *
     287 * @param string $string
     288 * @param string $search
     289 * @param string $style
     290 * @return string
     291 */
    285292function add_style( $string, $search, $style )
    286293{
     
    296303  {
    297304    $treatment = substr ( $remaining, 0, $start );
    298     $treatment = str_replace( $search, '<span style="'.$style.'">'.
    299                               $search.'</span>', $treatment );
     305    $treatment = preg_replace( '/('.$search.')/i',
     306                               '<span style="'.$style.'">\\0</span>',
     307                               $treatment );
    300308    $return_string.= $treatment.substr( $remaining, $start, $end-$start+1 );
    301309    $remaining = substr ( $remaining, $end + 1, strlen( $remaining ) );
     
    303311    $end   = strpos ( $remaining, '>' );
    304312  }
    305   $treatment = str_replace( $search, '<span style="'.$style.'">'.
    306                             $search.'</span>', $remaining );
     313  $treatment = preg_replace( '/('.$search.')/i',
     314                             '<span style="'.$style.'">\\0</span>',
     315                             $remaining );
    307316  $return_string.= $treatment;
    308317               
Note: See TracChangeset for help on using the changeset viewer.