SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Not Bad, eh? Justin Sampson's Avatar
    Join Date
    Aug 2000
    Location
    N.S., Canada
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,
    I'm trying to get highlight_string() to work, here's my code:
    PHP Code:
    <form action="<? echo "$PHP_SELF?>" method="POST">
    <input type="texbox" rows="6" cols="9" name="foo"><input type="submit">
    </form>
    Results:
    <?
    htmlspecialchars
    ($foo);
    highlight_string($foo);

    ?>
    But I get this error:

    Warning: Unexpected character in input: '\' (ASCII=92) state=1 in c:\webdocs\hilite.php on line 7

    Anyone know whats wrong?

    Thanks,
    Justin Sampson

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unfortunately highlight_string() needs to have <? ?> tags present in order to work, and it seems that you must replace \ with '' before it will work with that sort of character, I got it to work this way
    PHP Code:
    <form action="<?=$PHP_SELF?>" method="POST">
    <input type="texbox" rows="6" cols="9" name="foo"><input name="submit" type="submit" value="submit">
    </form>
    Results:
    <?
    if($submit) {
        
    $foo addslashes($foo);
        
    $foo htmlspecialchars($foo);
        
    $foo str_replace('\\'''$foo);
        
    highlight_string("<? print $foo; ?>");
        }
    ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Freddy, I also was trying to do this however there was a problem since the [*PHP] tags in vBulletin remove the \'s.

    I think you gotta put in the [*CODE] tags.

    Thanx Allot...

  4. #4
    Not Bad, eh? Justin Sampson's Avatar
    Join Date
    Aug 2000
    Location
    N.S., Canada
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, see, what I'm trying to do is add a [ php ] feature to my forum. I can get everything between the [ php ] and [/ php ] tags into a variable, just can't get the highlight to work.

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Justin so just add <? and ?> to each side of the var that holds the stuff betweeen the
    PHP Code:
     and 
    tags when using highlight_string() and remember to str_replace out any unwanted vars and then run highlight_string()
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •