Go Back   HTMLCenter Web Development Forums > Web Design and Development > Programming and Scripting

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 07-30-2008, 08:41 PM
Registered User
 
Join Date: Jul 2004
Posts: 224
higlighting problem: shouldn't highlight one letter at a time

What's wrong with this:
PHP Code:
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:
Code:
<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>
Reply With Quote

  #2 (permalink)  
Old 07-31-2008, 05:20 AM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,399
My first guess would be that $keyword is not really an array, but a string.

If you use a string in a scalar context (place a number in square brackets after the string name), it will use one letter from the string.

I do find it a bit strange that you're running the loop according to the count of a variable called "$bigWords", but you're utilizing a variable called $keyword inside.

Finally, unless your keyword will include a regexp at any point in time, you really should be using str_ireplace instead of preg_replace.
__________________
I hate Internet Explorer! Anyone with me?
Reply With Quote
  #3 (permalink)  
Old 07-31-2008, 11:02 AM
Registered User
 
Join Date: Jul 2004
Posts: 224
Quote:
Originally Posted by curtiss View Post
My first guess would be that $keyword is not really an array, but a string.

If you use a string in a scalar context (place a number in square brackets after the string name), it will use one letter from the string.

I do find it a bit strange that you're running the loop according to the count of a variable called "$bigWords", but you're utilizing a variable called $keyword inside.

Finally, unless your keyword will include a regexp at any point in time, you really should be using str_ireplace instead of 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.
Reply With Quote
  #4 (permalink)  
Old 07-31-2008, 08:07 PM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,399
Does that mean that you solved your problem, or do you still need more help?
__________________
I hate Internet Explorer! Anyone with me?
Reply With Quote
  #5 (permalink)  
Old 07-31-2008, 10:06 PM
Registered User
 
Join Date: Jul 2004
Posts: 224
Quote:
Originally Posted by curtiss View Post
Does that mean that you solved your problem, or do you still need more help?
I resolved it thanks.
__________________
Gilgal's website:
Wheel Of God
Now easy to post scripture verses!
Portfolio
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Minimum time to make live a Website in Internet hindi SEO - Search Engine Optimization 1 09-30-2007 12:43 PM
framespacing="0" problem solved cssiscool Programming and Scripting 4 06-14-2007 07:27 AM
Time Management-An essential factor for home based worker! ezyjobtrade Off-Topic 2 07-05-2006 12:10 AM
Time won't appear correctly kenwvs Programming and Scripting 6 07-01-2006 08:54 AM


All times are GMT -5. The time now is 04:30 AM.

 
KickApps
Clicky Web Analytics


Subscribe to our feed | add to myYahoo!

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
© 1997-2007 HTMLCenter