I have been racking my brain and can't figure this out???
I'm trying to <b> or <highlight> characters/words in my string and for some reason the <b> tag is getting replaced when the $q includes the character "b".
It also does the same for <span class=".... just reacts to different characters.
If anyone can help would be really great... or if you have better function???
<?php
$rows[0][0] = "The world is ending";
$rows[0][1] = "What should we do";
$rows[0][2] = "You are the best";
$rows[0][3] = "Turn left at the next exit";
$rows[1][0] = "You gave me life";
$rows[1][1] = "Will you be my friend";
$rows[1][2] = "I like you more everyday";
$rows[1][3] = "Is that a wig on your head";
$q = "a b c d";
$q_array = explode(" ", $q);
$q_array = array_unique($q_array);
$q_array = array_values($q_array);
$num_q = count($q_array);
foreach ($q_array as $key) $q_array1[] = "!($key)!i";
foreach($rows as $key){
$row .= "<tr>";
foreach($key as $str){
$str = preg_replace($q_array1, "<b>$1</b>", $str);
$row .= "<td>$str</td>";}
$row .= "</tr>";
}
echo "<table border=\"1\">$row</table>";
print_r($q_array1);
?>