<?xml> for XHTML Prevents PHP Code from Running

shawntc

Member
Messages
70
Reaction score
0
Points
6
When it comes to standards, I like to comply. As such, when I make an XHTML document, I begin it with this:

Code:
<?xml version="1.0" encoding="UTF-8"?>

However, this creates a problem. Whenever I try to put PHP code using <?php ... ?> the site will give me an error about the PHP parser on line 1, where the <?xml> tag is. Short of removing that tag, are there any work-arounds?

Thanks!
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
That's the problem with short tags. Since you can't change PHP directives (unless you have a VPS and perhaps paid account, but I'm not certain of the latter), there are various other solutions. One is to echo some part of the XML directive. A simpler is:
PHP:
<<?php ?>?xml ...>
which will work whether or not short tags are enabled. If you can rely on short tags being turned on (though this may come back to haunt you if you change hosts or the server config ever changes), you can use the even shorter:
PHP:
<<??>?xml ...>
 
Last edited:

shawntc

Member
Messages
70
Reaction score
0
Points
6
That's the problem with short tags. Since you can't change PHP directives (unless you have a VPS and perhaps paid account, but I'm not certain of the latter), there are various other solutions. One is to echo some part of the XML directive. A simpler is:
PHP:
<<?php ?>?xml ...>
which will work whether or not short tags are enabled. If you can rely on short tags being turned on (though this may come back to haunt you if you change hosts or the server config ever changes), you can use the even shorter:
PHP:
<<??>?xml ...>
Sounds good. I don't plan on relying on short tags.
 
Top