1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to display "<?xml version="1.0" encoding="utf-8"?>"

Discussion in 'PHP' started by bobby9101, Mar 5, 2007.

  1. #1
    I have a .php with <?xml version="1.0" encoding="utf-8"?> in it, not in inside of <?php ?>, but I get an error, because php is trying to read it as short tags, so how can I get it to be parsed as html?
    I don't want to have to put it in <?php and then echo it
     
    bobby9101, Mar 5, 2007 IP
  2. PhatDV

    PhatDV Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Only simple way I know of:

    <?= '<' . '?xml version="1.0" encoding="utf-8"?' . '>' ?>
    Code (markup):
    I know you specifically said you didn't want to echo it.

    The only other way would be to store the tags in a seperate file from your script, read the file in and send it straight to output. That way the tags wouldn't be parsed.
     
    PhatDV, Mar 5, 2007 IP
  3. Yeldarb

    Yeldarb Active Member

    Messages:
    209
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #3
    Turn off short tags?
     
    Yeldarb, Mar 5, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Try setting this on top of your script.

    
    ini_set('short_open_tag', '0');
    
    PHP:
     
    nico_swd, Mar 5, 2007 IP
  5. bobby9101

    bobby9101 Peon

    Messages:
    3,292
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i am echoing it for now, but am still open to suggestions
     
    bobby9101, Mar 5, 2007 IP
  6. bobby9101

    bobby9101 Peon

    Messages:
    3,292
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thanks nico, but i know I saw somewhere some way to escape it in html.
     
    bobby9101, Mar 5, 2007 IP
  7. wmtips

    wmtips Well-Known Member

    Messages:
    598
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #7
    You can use heredoc syntax for that, all data will be outputted "as is":

    
    <?
    
    echo <<<EOL
    <?xml version="1.0" encoding="utf-8"?>
    
    EOL;
    
    echo 'code';
    
    ?>
    
    PHP:
    But I would recommend using templates to separate your presentation layer and code. Simple solution also is a file inclusion:

    header.xml contents:
    
    <?
    
    include 'header.xml';
    
    echo 'code';
    
    ?>
    
    PHP:
     
    wmtips, Mar 6, 2007 IP
  8. Smaaz

    Smaaz Notable Member

    Messages:
    2,425
    Likes Received:
    160
    Best Answers:
    0
    Trophy Points:
    250
    #8
    $questionmark = "?";
    echo "<".$questionmark."xml version=\"1.0\" encoding=\"utf-8\"".$questionmark.">";
    PHP:
     
    Smaaz, Mar 6, 2007 IP
  9. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #9
    ^^ If he wanted to echo it, he could do:
    
    
    echo '<?xml version="1.0" encoding="utf-8"?>';
    
    PHP:
    But he doesn't want to echo it...
     
    nico_swd, Mar 6, 2007 IP