function highlight($content,$word){
if(is_array($word)){
$num=count($word);
$lighted[0]=$content;
for($j=0;$j<$num;$j++){
$k=$j+1; //$kを$jの先に進めておく。
//一単語ずつハイライトしていったものを格納。
$lighted[$k]=str_replace($word[$j],
"<span class='highlight'>{$word[$j]}</span>",$lighted[$j]);
}
return $lighted[$num];
}
else{
$lighted=str_replace($word,"<span class='highlight'>{$word}</span>"
,$content);
return $lighted;
}
}
0 件のコメント:
コメントを投稿