What's wrong with this: for($m=0; $m < count($bigWords); $m++){ $strText = preg_replace("/(".$keyword[$m].")/i", "<span class=\"\" id=\"\" style=\"color:".$COLORS[$m]."; font-weight:bold;\">$1</span>", $strText); echo "<br />"; echo $strText; } PHP: It's highlighting one letter at a time: <span class="" id="" style="color:red; font-weight:bold;"></span> t<span class="" id="" style="color:red; font-weight:bold;"></span> h<span class="" id="" style="color:red; font-weight:bold;"></span> e<span class="" id="" style="color:red; font-weight:bold;"></span> <span class="" id="" style="color:red; font-weight:bold;"></span> w<span class="" id="" style="color:red; font-weight:bold;"></span> h<span class="" id="" style="color:red; font-weight:bold;"></span> o<span class="" id="" style="color:red; font-weight:bold;"></span> <span class="" id="" style="color:red; font-weight:bold;"></span> a<span class="" id="" style="color:red; font-weight:bold;"></span> n<span class="" id="" style="color:red; font-weight:bold;"></span> d<span class="" id="" style="color:red; font-weight:bold;"></span> <span class="" id="" style="color:red; font-weight:bold;"></span> b<span class="" id="" style="color:red; font-weight:bold;"></span> u<span class="" id="" style="color:red; font-weight:bold;"></span> Code (markup):
What is the $keyword variable..? It seems like it's a string and not an array so doing $keyword[$m] would do one letter at a time from the string. Since you're doing it from count($bigWords), shouldn't you be using $bigWords[$m] in the preg_replace?
I realized when I pasted that section the $keyword wasn't mentioned before. And echo $strtext should be placed outside the for loop.