SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    USA
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Highlight problem still no one has been able to answer

    What I want to do is very simple...but for some reason no one (here and other places) has been able to successfully solve the problem. All help would be appreciated.

    What do I want to do?

    Highlight PHP code pulled from a mysql database.

    Basically right now, I tried it and it doesn't work....see with highlight_string you need the <? php ?> tags.

    Let's say i'm fetching a row from a database.

    PHP Code:
    while($row mysqli_fetch_row($result)) 

            echo 
    $row[0];

    Now..I want to highlight that row because it contains PHP code. so I do this:
    highlight_string($row[0]); -- doesn't work. I think cuz you need <? ?> tags.

    echo highlight_string("<? php $row[0] />") wont work..it'll convert $row[0] into a string.

    i've tried almost everything..with no success.

    Please help me! No one's been able to do it yet.


    Baggy!

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    USA
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    problem fixed thanks to a guy on webhostingtalk.com. solution:

    PHP Code:
    $row[0] = '<?php '.$row[0].' ?>';
    highlight_string($row[0]);
    OR

    PHP Code:
       echo highlight_string('<?php '.$row[0].' ?>', true);
    Just add <? php <? to beginning and end.

  3. #3
    SitePoint Enthusiast DoubleM's Avatar
    Join Date
    Mar 2006
    Location
    West -USA
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by baggypants303
    What I want to do is very simple...but for some reason no one (here and other places) has been able to successfully solve the problem. All help would be appreciated.

    What do I want to do?

    Highlight PHP code pulled from a mysql database.

    Basically right now, I tried it and it doesn't work....see with highlight_string you need the <? php ?> tags.

    Let's say i'm fetching a row from a database.

    PHP Code:
    while($row mysqli_fetch_row($result)) 

            echo 
    $row[0];

    Now..I want to highlight that row because it contains PHP code. so I do this:
    highlight_string($row[0]); -- doesn't work. I think cuz you need <? ?> tags.

    echo highlight_string("<? php $row[0] />") wont work..it'll convert $row[0] into a string.

    i've tried almost everything..with no success.

    Please help me! No one's been able to do it yet.


    Baggy!
    your orginal code was almost correct!
    you just added a space character after the '?' here:
    echo highlight_string("<? php $row[0] />")
    and that was the problem. any way I'm glad that your problem is solved now
    <?php5 echo 'I am just a very newbie ! '; ?>


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
  •