XHTML
Specifications
Articles of interest
Validators
Other
How I use XHTML on my site
Even though it's "considered harmful" to serve XHTML as text/html, if a browser doesn't support application/xhtml+xml (i.e. IE), you can't serve it with the appropriate MIME type. So, I do sniffing:
<?php function sendContentType($type, $charset = 'UTF-8'){ $types = array( #just for convenience 'rss'=>'application/rss+xml', 'xhtml'=>'application/xhtml+xml', 'atom'=>'application/atom+xml', 'html'=>'text/html' ); $xml_types = array('application/rss+xml','application/atom+xml'); $xml_fallbacks = array('application/xml', 'text/xml');
$type = g($types, $type, $type); $accept = g($_SERVER, 'HTTP_ACCEPT'); if($accept) $accept = strtolower($accept);
# if accept header isn't given, there's nothing you can do. # If it's an "HTML" mime type, send text/html. Otherwise, send the given mime type if($type == $types['xhtml'] and (!$accept or (strpos($accept, $type) === false))){ $type = $types['html']; }elseif($accept and in_array($type, $xml_types)){ #if you're sending an xml-based file format, but the client doesn't accept the specific mime type, # just send as XML array_unshift($xml_fallbacks, $type); foreach($xml_fallbacks as $test){ if(strpos($accept, $test) !== false){ $type = $test; break; } } }
header("Content-type: $type; charset=$charset"); return $type; }
#Then in my header template $content_type = sendContentType('xhtml'); if($content_type != 'text/html'){?><?xml version="1.0" encoding="UTF-8"?><?php }?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> ... and so on
g defined here
And, here's a standalone beginning incantation for XHTML so I don't have to piece it together from my header source every time:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>Testing</title>
</head>
<body>
...
</body>
</html>
Page last edited: February 19, 2006 (utc)
|