Include '<?' in a string literal

Discussion in 'PHP' started by Rocketo, Sep 1, 2007.

  1. #1
    What's the cleanest way to include '<?' in a string literal ?
    Simply using $foo = "some text <?" wont work.
     
    Rocketo, Sep 1, 2007 IP
  2. gopher292

    gopher292 Peon

    Messages:
    64
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $foo="some text <"."?";

    would work. :)
     
    gopher292, Sep 1, 2007 IP
  3. Rocketo

    Rocketo Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks pal.
     
    Rocketo, Sep 1, 2007 IP
  4. Rocketo

    Rocketo Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hmmm, I'm still having problems with this one.

    Ok, so now I have the variable set with this:
    $foo="some text <"."?";
    The problem comes when I try to echo the variable:
    echo $foo;

    IE correctly shows: 'some text <?'
    FireFox shows: 'some text'
    Opera never stops loading. When I press stop it shows: 'some text'

    I don't get it. What's going on?
    Can anyone give a clue?
     
    Rocketo, Sep 1, 2007 IP
  5. James.Blant

    James.Blant Active Member

    Messages:
    250
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #5
    you should using unicode chars for show characters .
    just view source of this page and you can find : '&lt;?' for showing <?
     
    James.Blant, Sep 1, 2007 IP
  6. Rocketo

    Rocketo Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yep, you're right.
    I should have used:
    echo htmlspecialchars($foo);

    Thanks.
     
    Rocketo, Sep 1, 2007 IP