- Kim Bach . Org - http://www.kimbach.org -

PHP blues – drawing a blank

Posted By Kim On December 15, 2007 @ 11:00 am In Blogs,Bookmarks,Computere og Internet,Hackers,Kim Blog (English),Open Source,Technology | 3 Comments

Software development can be extremely frustrating, and it might be true that the computer only does what you tell it to do, but these days a lot of people, besides yourself, are telling the computer what to do, a fact that complicates matters “somewhat” (understatement of the year).

The following experience documents a case, where I was sure that I wasn’t doing anything wrong, and you could argue that I didn’t, I just didn’t know any better, but thanks to the community I solved the problem.

The setting

I’ve recently begun doing some PHP programming, and I like it a lot, mostly because of all the wonderful community. it’s my gut feeling that I find answers to my questions much faster when I have PHP related questions, compared to .NET questions.

So I was experimenting with generating some XML code from PHP, but when I gave the URL to the W3C validator, it told me that the XML wasn’t well-formed, and that it was the header that was the problem.

I couldn’t see anything wrong, until I took a closer look. There was a mysterious space prefixed the output when I did a View/Source, a space that I for sure knew I didn’t echo. Hmm…

I tried several things, including flushing the output, but nothing helped.

Then it dawned on me: it’s very likely that someone else has had this problem, and if they did, for sure they would have the generosity to share it, so Google to rescue.

I googled: problem php output leading blank [1], and hit number two yielded this article:

Script for removing blank spaces before and after PHP tags « memento [2]

The solution

It turns out that PHP is quite sensitive if you, by accident, leave prefixed or sufficed blank spaces outside the starting and ending php tags.

So I went through my PHP files, luckily I only have two, made sure there were no leading or trailing blanks og lines, and I get well-formed XML now.

This is a rather annoying bug in, or should I say feature of, PHP, and it exists in both PHP4 and PHP5.

Once again the community came through, without it I’d still be drawing blanks.

And I love the drawing [3] on the memento site, it doesn’t get geekier, and I think I’ll remember to strip leading and trailing blanks now.

I’m still looking for a modern development environment for PHP development (e.g. sourcecode debugging). PHPEclipse [4], a plug-in for the Eclipse [5] development environment, should provide a relatively modern development environment, even though it’s not up to the standards set by Microsoft VisualStudio, that I’m so accustomed to, Microsoft has spoiled me.

Article printed from Kim Bach . Org: http://www.kimbach.org

URL to article: http://www.kimbach.org/2007/12/15/php-blues-drawing-a-blank/

URLs in this post:

[1] problem php output leading blank: http://www.google.dk/search?ie=UTF-8&oe=UTF-8&sourceid=navclient&gfns=1&q=problem+php+output+leading+blank

[2] Script for removing blank spaces before and after PHP tags « memento: http://ragrawal.wordpress.com/2007/11/07/script-for-removing-blank-spaces-before-and-after-php-tags/#comment-80

[3] the drawing: http://ragrawal.files.wordpress.com/2007/11/blank_spaces2.jpg

[4] PHPEclipse: http://www.phpeclipse.de

[5] Eclipse: http://www.eclipse.org

[6] : http://www.kimbach.org/2007/12/15/php-blues-drawing-a-blank/?share=facebook

[7] : http://www.kimbach.org/2007/12/15/php-blues-drawing-a-blank/?share=twitter

[8] : http://www.kimbach.org/2007/12/15/php-blues-drawing-a-blank/?share=google-plus-1

[9] : http://www.kimbach.org/2007/12/15/php-blues-drawing-a-blank/?share=tumblr

[10] : http://www.kimbach.org/2007/12/15/php-blues-drawing-a-blank/?share=pinterest

[11] : http://www.kimbach.org/2007/12/15/php-blues-drawing-a-blank/#print

[12] : http://www.kimbach.org/2007/12/15/php-blues-drawing-a-blank/?share=email