I create my RSS(XML) documents using PHP, so the information is always dynamic.
However, I ran into a problem when attempting to use the standard XML declaration, in my XML documents:
Since the XML declaration is similar to the PHP declaration,
... a big fat parse error is the only obvious output.
As you might guess, the question mark is what causes a bump. To get around this, one of two things has to be done:
- Make a small change in my php.ini file, or an .htaccess file.
- Echo a true string literal to the page, so PHP doesn’t parse the question marks.
Echo a string literal
Since I don’t have (or I am not sure if I have) access to my php.ini file, I went with option 2:
print ("\n");
or...
echo '\n';
This seems to correct the issue.
php.ini or .htaccess
However, I still would like to know how to do it with step 1. I have done some research from the PHP end, and it seems there is a setting within the php.ini file, which needs to be turned on or off.
Also, I have heard there is a line in an .htaccess file that can do the same thing.
I will be looking into it.
My technical meanderings and other nonsense. Published since 2002. No, really. I'm *that* internet-old. I remember the days of
When you use
in a single-quoted string (‘) it will not be parsed as a newline, remember that.
And btw: look in to short-tags ;) (for php.ini/htaccess)
What IS the htaccess script that I need?
And, everyone, please ignore the ‘echo’ example from above… I totally messed that one up. Like Blitz said, I don’t need the newline (
), and I don’t even think I need to escape those double quotes… but I could be wrong on that one.
http://forums.devarticles.com/archive/t-5039/XHTMLPHP-error
This should solve your .htaccess php/xml problem. I had the same issue.
does the trick for me.
OK, that code should all have been on one line, but you get the idea :)
echo ‘< ?xml version="1.0" encoding="utf-8"?>
‘;
ive added < ?php ?> at both ends it does it for me! thanks!
Thanks, Matt. However, your suggestion does not fully work.
This does:
<?php echo "<?xml version="1.0" encoding="utf-8"?>"; ?>
None of your suggestions work fully. I have tried all the above suggestions, it opens the page without error BUT at the very top-left corner of the page it prints “; ?>
How do you fix that then?
The following has been working for me, for years. I have used Dreamhost and Media Temple as web hosts.
In
.htaccessfile:And in your PHP file:
<?php header("Content-type: text/xml"); print ("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); ?>Hope that helps clear this one up!