highlight_string

Discussion in 'PHP' started by aaron_nimocks, Oct 19, 2006.

  1. #1
    Alright I am trying to get this highlight_string function to work without any luck at all. Here is my code without the highlight_string in there.

    
    {	
    $output .= "
    <hr>
    <div class='grey_top'></div>
    <div class='grey'>
    <a href='$row->website'>$row->name</a> says:<br><br>
    $row->comment
    </div>
    ";
    }
    echo $output;
    
    PHP:
    This is the page I am trying to get work.

    http://www.phpelf.com/echo.php

    Basically you can post a comment and I would expect php code to be in that comment. Now when I return it I would like just the comment portion to be highlighted.

    Any ideas?
     
    aaron_nimocks, Oct 19, 2006 IP
  2. klown

    klown Peon

    Messages:
    2,093
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Here is some code, perhaps you need to make sure you input a <?php ?> where you want php code to be highlighted.

    <?php
    $comment="Here is a comment about stuff ha ha ha. Oh some php code sounds like fun. <?php echo 'some stuff about something in php'; ?> ";
    highlight_string ($comment);
    ?>
    PHP:
    the code above takes the comment and just highlights the part contained in the <?php ?> tags.
     
    klown, Oct 19, 2006 IP
  3. aaron_nimocks

    aaron_nimocks Im kind of a big deal Staff

    Messages:
    5,563
    Likes Received:
    627
    Best Answers:
    0
    Trophy Points:
    420
    #3
    Well it displays properly when I have it out of the while. But when I put it in it dont work for some reason.

    Works like this..

    				
    while ( $row = mysql_fetch_object($result) )
    {	
    $string_comment = $row->comment;
    echo "
    <br><div class='grey_top'></div>
    <div class='grey'>
    <a href='$row->website'>$row->name</a> says:<hr><br>
    </div>";
    }
    	
    highlight_string($string_comment);
    
    PHP:
    But dont work when I put that line inside the While.
     
    aaron_nimocks, Oct 19, 2006 IP
  4. aaron_nimocks

    aaron_nimocks Im kind of a big deal Staff

    Messages:
    5,563
    Likes Received:
    627
    Best Answers:
    0
    Trophy Points:
    420
    #4
    I got it. Just had to break the echo and then do the highlight then start the echo back up.

    
    while ( $row = mysql_fetch_object($result) )
    {	
    $string_comment = $row->comment;
    echo "
    <br><div class='grey_top'></div>
    <div class='grey'>
    <a href='$row->website'>$row->name</a> says:<hr><br>";
    highlight_string($string_comment);
    echo "</div>";
    }
    
    PHP:
    That only killed an hour. :)
     
    aaron_nimocks, Oct 19, 2006 IP
  5. klown

    klown Peon

    Messages:
    2,093
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I know what you mean, seems like the smallest problems take up a lot of time. I tend to just take a break from coding for an hour or so when i cant seem to wrap my head around a problem i cant find. Works wonders i usually fix it in 10 seconds when i come back.
     
    klown, Oct 19, 2006 IP