Skip to content

Instantly share code, notes, and snippets.

@Wilfred
Created May 7, 2009 21:21
Show Gist options
  • Save Wilfred/108393 to your computer and use it in GitHub Desktop.
Save Wilfred/108393 to your computer and use it in GitHub Desktop.
<?php
//based on http://lists.w3.org/Archives/Public/www-validator/2007Jul/0208.html
$mime = 'text/html'; //fallback
// set xhtml mimetype if browser claims it accepts it:
if(!empty($_SERVER['HTTP_ACCEPT']) && stristr($_SERVER['HTTP_ACCEPT'],'application/xhtml+xml')) {
$mime = 'application/xhtml+xml';
}
// or if it is the validator:
if (stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator") OR stristr($_SERVER["HTTP_USER_AGENT"],"W3C_CSS_Validator") OR
stristr($_SERVER["HTTP_USER_AGENT"],"WDG_Validator")) {
$mime = "application/xhtml+xml";
}
// and put into http header:
header('Content-Type: '.$mime.';charset=utf-8');
// xml prolog:
echo("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
// only add doctype if we are serving xhtml -- want to trigger quirks mode otherwise
// unnecessary?
if ($mime == 'application/xhtml+xml') {
echo ('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">');
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment