View Full Version : How to display "<?xml version="1.0" encoding="utf-8"?>"
bobby9101
Mar 5th 2007, 5:08 pm
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
PhatDV
Mar 5th 2007, 5:20 pm
Only simple way I know of:
<?= '<' . '?xml version="1.0" encoding="utf-8"?' . '>' ?>
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.
Yeldarb
Mar 5th 2007, 5:37 pm
Turn off short tags?
nico_swd
Mar 5th 2007, 5:45 pm
Try setting this on top of your script.
ini_set('short_open_tag', '0');
bobby9101
Mar 5th 2007, 5:48 pm
i am echoing it for now, but am still open to suggestions
bobby9101
Mar 5th 2007, 5:51 pm
thanks nico, but i know I saw somewhere some way to escape it in html.
wmtips
Mar 6th 2007, 7:54 am
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';
?>
But I would recommend using templates to separate your presentation layer and code. Simple solution also is a file inclusion:
header.xml contents:
<?xml version="1.0" encoding="utf-8"?>
<?
include 'header.xml';
echo 'code';
?>
Smaaz
Mar 6th 2007, 8:15 am
$questionmark = "?";
echo "<".$questionmark."xml version=\"1.0\" encoding=\"utf-8\"".$questionmark.">";
nico_swd
Mar 6th 2007, 8:16 am
^^ If he wanted to echo it, he could do:
echo '<?xml version="1.0" encoding="utf-8"?>';
But he doesn't want to echo it...
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.