Generating XML via PHP throws an HTTP-500.
Published on by Karl Lindmark. 0 commentsI’ve been working on an easy way for the translators to translate the strings.xml for my current, as well as upcoming, projects. It worked perfectly on my localhost, but when I uploaded it onto this server… well, let’s just say that it didn’t quite work as planned.
Consider the following code.
<?xml version="1.0" encoding="utf-8"?>
At first I didn’t get an error message at all, but when I finally managed to get it to actually speak to me, here’s what it said:
Parse error: syntax error, unexpected T_STRING in /translate/download.php on line 1
Makes sense? No, not at all at first glance, however if you consider the fact that shorttags might be allowed on a host, the actual code would be parsed in the following way:
<?php xml version="1.0" encoding="utf-8"?>
As you can see, the code above would indeed be invalid when it comes to php, and there are two solutions (that I know of) available. One would be to switch off the shorttags-option, so that only will be considered a valid php-tag (and it should only be that way too in my opinion). The second one would instead have you output the xml-header programmatically:
<?php echo '<?xml version="1.0" encoding="utf-8"?>'; ?>
Hope this helps someone else out, as it did trouble me a bit until I managed to get ahold of an error message.