Yes. Here's a slightly more simplified version of the script I wrote to take care of it. Basically it automatically detects whether to send as html or xhtml, and can be overriden by the query string (for testing, etc).
PHP Code:
<?php
$qstring=stripslashes($_SERVER['QUERY_STRING']);
$usehtml=($qstring=='html');
$usexhtml=($qstring=='xhtml');
if(!$qstring=='')$robots='<meta name="robots" content="noindex,nofollow,noarchive" />';
else $robots='<meta name="robots" content="index,follow,noarchive" />';
if(!$usehtml && !$usexhtml){
$usexhtml=stristr($_SERVER['HTTP_ACCEPT'],'application/xhtml+xml');
if($usexhtml && preg_match("/text\/html;q=0(\.[1-9]+)/i",$_SERVER["HTTP_ACCEPT"],$qtest2)){
if(preg_match("/application\/xhtml\+xml;q=0(\.[1-9]+)/i",$_SERVER["HTTP_ACCEPT"],$qtest1))
$usexhtml=($qtest1[1]>=$qtest2[1]);
else
$usexhtml=false;
}
}
if ($usexhtml) {
$conttype='application/xhtml+xml';
$dtype="<?xml version='1.0' encoding='utf-8'?". '>'. chr(10). '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'. chr(10). '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'. chr(10);
$htmltg='<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'. chr(10);
}
else {
$usehtml=true;
$conttype='text/html';
$dtype='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'. chr(10);
$htmltg='<html lang="en">'. chr(10);
}
header('Content-type: '. $conttype);
header('Cache-Control: must-revalidate');
header('Expires: '. gmdate('D, d M Y H:i:s',time()+3600). ' GMT');
echo $dtype. $htmltg;
?>
Here's my website's first real page: Toshiba BDX3200KY Firmware. It does not yet implement the correct design of the website, just an example of the HTML/XHTML duality in action (try the W3 verification links at the bottom of the page). Also, only mozilla actually highlights the XHTML source code correctly (if you view it). Chrome and Opera's source viewer incorrectly stops highlighting at the script tag as if the rest of the website is a javascript! Yet they parse the website correctly.
Bookmarks