SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    highlighting 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>
    Compare bible texts (and other tools):
    TheWheelofGod

  2. #2
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    if $keyword[$m] evaluates to a blank string, then your regular expression will match all of the spots BETWEEN characters.

    what exactly are you trying to do? do you have an array of words you want highlighted?
    Check out our new Industry News forum!
    Keep up-to-date with the latest SP news in the Community Crier

    I edit the SitePoint Podcast

  3. #3
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by longneck View Post
    if $keyword[$m] evaluates to a blank string, then your regular expression will match all of the spots BETWEEN characters.

    what exactly are you trying to do? do you have an array of words you want highlighted?
    I realized that the echo had to be taken out of the loop.
    Compare bible texts (and other tools):
    TheWheelofGod

  4. #4
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    um, what? what you said doesn't fix the problem and doesn't answer my question.
    Check out our new Industry News forum!
    Keep up-to-date with the latest SP news in the Community Crier

    I edit the SitePoint Podcast

  5. #5
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your counting from one variable and using another to get the data. Surely you should use the same.

    Code php:
    $bigWords = array(
        "welcome",
        "sitepoint"
    );
    $strText = "welcome to sitepoint.com";
    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>", $strText);
        echo "<br />";
        echo $strText;
    }


  6. #6
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I needed to place the echo $strtext outside the for loop.
    Compare bible texts (and other tools):
    TheWheelofGod


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •