Really valid XHTML

For an XHTML page to be valid, it should of course, validate. (Funny sentence! <g>)

An oft-forgotten rule though is that XHTML documents are XML documents, and because of that, they must be served using the mime-type application/xhtml+xml. Internet Explorer predictably, chokes on this, therefore, you need some selective magic to accomplish this. If you’ve got PHP on your webserver, the following script will do the deed:


/*Send application/xhtml+xml to compliant browsers, text/html to others*/
if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
  header("Content-type: application/xhtml+xml; charset=utf-8");
  print "< "."?xml version=\"1.0\" encoding=\"UTF-8\"?".">";
}
else {
  header("Content-type: text/html; charset=utf-8");
}

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s