lucy24 - 7:19 pm on Apr 15, 2013 (gmt 0)
If I copy the code into a new file (test.php) it works perfectly, just like the other pages.
The entire code? Not just the if/else bit?
or this page has probably a BOM element on top of it
I'll be darned. I would not have thought of the BOM-- except that another thread linked to w3c's discussion of it.* If your code works fine in a new document, an invisible character may well be the problem. Does it work if you paste the entire page text into a new page and give it the name of the old one? If so, the problem has fixed itself :)
:: memo to self: remember BOM the next time a page displays inexplicably ::
If you open the page locally in a browser and manually set the encoding to Latin-1-- or anything other than UTF-8 or -16 --any nasty invisible characters should jump out loud and clear.
* At long last I understand why the same character is both the BOM and the Zero-Width Nonbreaking Space. It's because it is the same character; it's just been repurposed.