Text
|
|
|
|
<?php
function highlight($needle, $hystack, $hl) {
$needle_length = strlen($needle);
$cmp_hs = strtolower ($hystack);
$cmp_hl = strlen ($hystack);
$cmp_ne = strtolower ($needle );
$cmp_nl = strlen ($needle );
$i=0;
$c=0;
while($i<=$cmp_hl) {
if(substr($cmp_hs,$i,$cmp_nl)==$needle) {
$to_bold_position[$c] = $i;
$c++;
}
$i++;
}
$i=0;
$temp='';
do {
$j = $i - 1;
$between = $to_bold_position[$i] - $to_bold_position[$j];
$temp2 = substr($hystack,$to_bold_position[$j],$between);
$temp .= eregi_replace($needle,"",$temp2);
$temp .= "$hl[0]".substr($hystack,$to_bold_position[$i],$cmp_nl)."$hl[1]";
$i++;
} while($i!=$c);
$i=$i-1;
$rest = $cmp_hl-$cmp_nl;
$last = $to_bold_position[$i]+$cmp_nl;
$temp .= substr($hystack,$last,$rest);
return $temp;
}
?>
|
|
|
Usage Example
|
<?php
include("highlight.php3");
$bt[0]="<b>";
$bt[1]="</b>";
echo highlight("test","dies ist ein test - zum testen der highlightfunktion",$bt); ?>
|
|
|
Rate This Script
|
|
|
|