Oh great, the (X)HTML validator is broken. I use a variation of Mark Pilgrim's code to check if the user-agent supports 'application/xhtml+xml':
<?php
if(strpos($_SERVER['HTTP_ACCEPT'],'application/xhtml+xml') !== false)
header("Content-type: application/xhtml+xml");
else
header("Content-type: text/html");
?>
The validator must not be sending an 'application/xhtml+xml' Accept header, because my page is being returned as text/html. The validator then complains that I have no DOCTYPE declaration, even though I'm using one of the declarations included in their list. If I unconditionally return the page with an 'application/xhtml+xml' Content-type, the validator correctly validates the page. What's going on here?
Update: It turns out there's an error in Mozilla's "view source" feature! I couldn't figure out why my page wasn't validating. I tried validating Simon's page, which validated. I finally checked the "show source" feature of the validator, and it turned out I was getting the following PHP notice (reformatted slightly):
<br />
<b>Notice</b>: Undefined index: HTTP_ACCEPT
in <b>[filename]</b> on line <b>2</b><br />
which Mozilla's "view source" didn't show! It just showed three blank lines at the top of the page. It turns out that the validator doesn't send any Accept header at all, so I changed the above code to (reformatted slightly):
<?php
if(isset($_SERVER['HTTP_ACCEPT']) and
strpos($_SERVER['HTTP_ACCEPT'],'application/xhtml+xml') !== false)
header("Content-type: application/xhtml+xml");
else
header("Content-type: text/html");
?>
And that made it work.
I've almost decided that viewing PHP's notices are more trouble than they're worth. Any code I release should be developed with as strict a level of error messages as possible, but there's no reason I should have to put up with it in my code if I don't want to. Though, it's not clear how to develop with strict errors on without all my pages having that level of error messages.
Update: Maybe rather than going straight to 'text/html' I should be going to something like 'text/xml' first.
Testing comment posting to make sure I still validate.