PHP and extra linefeed

I was working yesturday in PHP and came across an interesting problem and it took some time to figure out what was going on.

I had a system that was doing ajax calls to back-ends to show results on web pages. And the system has a php file to be included, that took care of opening config files and open database and stuff. And I needed to have one other file included to add some code in some places.

So the code was (in i_db.php):

Not to complicated. But now all my ajax backends (that also included this file – the i_db.php file) started to fail. And the error code was that firefix could not Parse the XML. The error message was:

And this was shown in firebug console. Where did this come from?

Well after spending almost 2 hours trying to figure out of it was the include or if one could use require or what to do I finally came across the answer.

If you end a php file in “?>” and add an extra space after the > php will add an extra new line automatically.

I am not sure why or if it even is well documented anywhere but that’s what it does and removing that solved my problem.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.