...

View Full Version : highlighting problem: shouldn't highlight one letter at a time



gilgalbiblewhee
07-31-2008, 02:42 AM
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;
}
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>

Apothem
07-31-2008, 02:58 AM
$strText = preg_replace("/(".$keyword[$m].")/i", "<span class=\"\" id=\"\" style=\"color:".$COLORS[$m].";

Question: Why doesn't the preg_replace have it's matching parenthesis? Also, where does $keyword derive from? What is in it, to be exact.

gilgalbiblewhee
07-31-2008, 03:06 AM
$strText = preg_replace("/(".$keyword[$m].")/i", "<span class=\"\" id=\"\" style=\"color:".$COLORS[$m].";

Question: Why doesn't the preg_replace have it's matching parenthesis? Also, where does $keyword derive from? What is in it, to be exact.

Oh yeah. Actually the semicolon is part of the style attribute:

$strText = preg_replace("/(".$keyword[$m].")/i", "<span class=\"\" id=\"\" style=\"color:".$COLORS[$m]."; font-weight:bold;\">$1</span>\n", $strText);
You had some good questions. $keyword was not in the code this part was pasted but I forgot to change it. It should be:

$strText = $searchThese;
for($m=0; $m < count($bigWords); $m++){
$strText = preg_replace("/(".$bigWords[$m].")/i", "<span class=\"\" id=\"\" style=\"color:".$COLORS[$m]."; font-weight:bold;\">$1</span>\n", $strText);
echo "<br />\n";
echo $strText;
}
But this is causing a repetition:

the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt
The first Highlights only one word and the last highlights all that it should.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum