1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
|
function highlightPhrase ( $strHaystack, $strNeedle,
$strColor = '', $bCase = FALSE )
{
if ( empty ( $strColor ) )
{
// Standardfarbe: Rot
$strColor = 'ff0000';
}
$strModifier = '';
if ( $bCase )
{
// Modifikator "i": Groß- und Kleinschreibung ignorieren.
$strModifier = 'i';
}
$strQuotedNeedle = preg_quote ( $strNeedle, '/' );
$strPattern = '/' . $strQuotedNeedle . '/' . $strModifier;
$strReplacement = '<span style="color: #' . $strColor . ';">$0</span>';
return preg_replace ( $strPattern, $strReplacement, $strHaystack );
}
|