<< Back To All Blogs
PHP and XML: Be very aware of your spacing
Saturday, March 22nd, 2008
I have been working on an XML API for a project that I am working on and was consistently receiving invalid XML because the first line of my XML document contained a space: hence it was not valid XML.
After looking around on the web I found nothing of relevance to me... most of the people that were having this issue were using an open source CMS, which didn't help me because I have my own internally-written system that I use.
After going through a TON of code, I found that 2 of my files that were being recursively included had an extra newline at the end of the file. I have a large set of classes and functions that are included globally on all my sites to make things much easier on me, and this newline was being propagated into my XML file when I included these files at the top of my XML document for output.
To make a long story short... do not leave extra new lines in any files you will be including, either at the beginning or the end of the file.
Currently no comments.
Add A Comment
Email Address: (not public, used to send notifications on further comments)
Enter the text above, except for the 1st and last character: