KBD

Keith Devens .com

Sunday, November 23, 2008 Flag waving
Don't panic. – Douglas Adams (The Hitchhiker's Guide to the Galaxy)

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)

Index

A B C D E F G H I J L M N O P R S T U V W X

All pages

A

  1. About
  2. Acno's Energizer
  3. Artificial Intelligence
  4. ASP.NET
  5. Atom

B

  1. Bash
  2. Belief systems
  3. Bookmarklets
  4. Build tools

C

  1. C and C++
  2. C#
  3. C++ Reference
  4. Calvinism
  5. Cars I want to consider
  6. CGI
  7. character sets
  8. Chess
  9. Christian Reconstruction
  10. Christian Resources
  11. Chronicles of Narnia
  12. Color tools
  13. Computer Science
  14. Cornelius Van Til
  15. CSS - Cascading style sheets
  16. CSSTabs

D

  1. Database
  2. Differencing programs
  3. Documentation standards
  4. Downloads
  5. Dualities
  6. Dvorak keyboard

E

  1. E-mail me
  2. Eclipse
  3. Eiffel
  4. Emacs
  5. Evolution
  6. Extension languages

F

  1. File extensions
  2. Firefox
  3. Formation: web form automation library for PHP
  4. Forth

G

  1. Greg Bahnsen
  2. GUI Toolkits
  3. Guns

H

  1. Hex editors

I

  1. Important articles or essays
  2. Installers
  3. Internet radio stations

J

  1. Java
  2. Javascript
  3. jEdit

L

  1. Linux
  2. Lisp
  3. Logical fallacies
  4. Lua

M

  1. Markup
  2. Miscellaneous Links
  3. mod_rewrite
  4. Movie theaters
  5. My comment policy
  6. My essential programs
  7. My resume

N

  1. Namespaces
  2. Naming conventions
  3. New Years 2000
  4. N^2 sort comparison

O

  1. Open Source License
  2. OPML

P

  1. Perl
  2. Philosophy
  3. PHP
  4. PHP Calendar (version 2.3)
  5. PHP XML Library, version 1.2b
  6. Pictures
  7. Postmillenialism
  8. Presuppositionalism
  9. Programming Fonts
  10. Programming languages
  11. Programming Resources
  12. Punta Cana
  13. Python

R

  1. RDF
  2. REBOL
  3. Reflex game
  4. Regular expressions
  5. Religion
  6. RFCs
  7. Robot Exclusions
  8. Roman Catholicism
  9. Ruby

S

  1. Scala programming language
  2. Science
  3. Shorthand
  4. Skydiving, August 28, 2000
  5. Software I've written
  6. SPAM
  7. SQLite
  8. StructuredText

T

  1. Tabs vs Spaces
  2. Tcl/Tk
  3. Tea
  4. Text Editors
  5. TextDrive
  6. The Big Bang
  7. The naked street
  8. Theonomy
  9. Tools of communication

U

  1. Unicode
  2. URL Design

V

  1. Version control systems
  2. VI text editor
  3. Virtual machines

W

  1. WeblogUrls
  2. Wiki
  3. WikiBlogIntegration
  4. World of Warcraft
  5. wxWidgets

X

  1. XHTML
  2. XML
  3. XML to PHP translator
  4. XML-RPC
  5. XML-RPC Library for PHP (v 2.5)

Generated in about 0.049s.

(Used 4 db queries)

mobile phone