XHTML/HTML

Tags: , January 7, 2005 (20 comments)

There has always been a lot of discussion about which one to use, and people have attacked this from different angles, with arguments including:

  • Internet Explorer enters "Quirks Mode" when an XHTML document has the XML prologue, yet has a 70% marketshare
  • If there's a slight error in a XHTML page, being correctly served as application/xhtml+xml browsers which support it fail to render it
  • XHTML is the future, so why stay with HTML?

So, basically, if we were able to hand out equally valid XHTML 1.1 and HTML 4.01 Strict depending on whether the UA supports application/xhtml+xml, all our problems have gone? Wrong. Browsers that don't support CSS will still fail, so make sure you use structured, semantic mark-up, then, even without styles, it will 99% of the time, look alright, and be readable, and understandable :)

But, how are we meant to sniff wheather the UA supports application/xhtml+xml, and through that XHTML? Javascript? No, it can be disabled. So what? PHP, or another server side language.

If your server supports PHP, here's the code:

<?php
// Charset
$charset = 'utf-8';
 
function fix_code($buffer) {
   $str = (str_replace(" />", ">", $buffer));
   return (str_replace("xml:lang", "lang", $str));
}
if ((stristr($_SERVER["HTTP_ACCEPT"], 'application/xhtml+xml'))  || (stristr($_SERVER["HTTP_USER_AGENT"], 'W3C_Validator')) || (stristr($_SERVER["HTTP_USER_AGENT"], 'WDG_Validator'))) {
$mime = 'application/xhtml+xml';
} else {
$mime = 'text/html';
}
header ("Content-type$mime");
If ($mime == "application/xhtml+xml") {
echo '<?xml version="1.0" encoding="' . $charset . '"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
} else {
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">';
ob_start("fix_code");
}
?>
 
<html <?php if ($mime == "application/xhtml+xml") { echo'xmlns="http://www.w3.org/1999/xhtml"'; } ?> xml:lang="en">
 <head>
  <meta http-equiv="content-type" content="<?php echo $mime; ?>; charset=<?php echo $charset; ?>" />

I cleaned out this version, putting the settings at the top, making easier for someone who doesn't know PHP to use, but compromising a couple of milliseconds :P

If anyone can convert this to ASP they will be thanked, get the code put up in the post and be creditied for it...

The above represented my views at the time, however, things change, so please read XHTML/HTML Followup.

[Updated 10th January 2005 - Adding xml:lang to lang support]

[Updated 10th January 2005 - Bug Fix]

[Updated 2nd March 2005 - Mistakes pointed out by Mithoric]

[Updated 21st August 2005 - New Views]

Same Software, Newer Version

Tags: January 4, 2005 (7 comments)

So here we go, after a couple of months of redesignings, and a hell of a lot of XHTML, CSS and PHP.

While looking around the web, I found many sites used images? Why? They slow down loading of the page, when often the effect can be created using CSS, meaning the user downloads more, so, I set about creating a site with as few images as possible, after several tried and failed designs, I decided to cut out all the fancy crap and go back to simplicity, black text, white background.

I started by starting with a stock copy of WP 1.3-alpha-5, I opened the stylesheet, and deleted everything in it, uploaded it, and moved into Firefox, and using the Web Developer extension, enabling me to edit CSS in RT. I set all the margins and padding to 0px, to allow me to set every margin and padding on the site, although there isn't much padding throughout the whole entire site :P

Some of you remember by previous, neglected, boring blog, which used WP 1.2.0 stable, this, however, is running WP 1.5-beta-1 2005-01-03, the last part refering to the fact that this is infact a nightly, abit, one day out of date, but I've spent the last couple of days constantly updating it, so I'm giving myself a break from updating, although it'll be updated shortly... As for the neglect bit, I very much doubt that will happen, maybe I'll get distracted sometimes, but not disinterested :)

Anyhow, I think that's enough worthless information... :P

Page:  1 … 27 28