The Fastest Developer This Side Of My Skin
About 7 or 8 years ago, when XML and XHTML were still relatively new, I had the Idea of making a PHP5 class that would parse the HTTP-Accept
header sent by a visitor's Web Browser to see if it had a preference between HTML or one of the many subtypes of XHTML and then serve the requested document in the best supported format. It seemed like a fairly obvious and straightforward thing to want to do given that, back then, support for XML and XML-related technologies were horrendously inconsistent. Back then there were a lot of very stupid people saying very stupid things about the two languages often in an--incredibly ironic--effort to give the impression they knew more about the subject than anyone else. Things like HTML has been deprecated by the W3C and shouldn't be used any more
and XHTML isn't supposed to be used on the Web. It's for intranets
. Occasionally you'd see someone putting forward some good information that would be worth considering, but it was always quickly drowned out by the many other people regurgitating someone else's misinformation on why one should always be used and the other should never be used. I figured that if you published in in XHTML and had the document translate its self to whatever the user's browser supported best then it really didn't matter.
I wanted to be able to play around with the--what were at the time--new features that were made available in XHTML because of it being a reformulation of HTML in XML, but I didn't want to have to serve up unhelpful Get a better Browser
notices on lots of pages. The problem was that many of the related standards were new to me, PHP is a seriously messy language, and MSIE 6 had 90something% market share. For those of you who don't know or have forgotten, MSIE 6 was basically the crack-head of browsers; it thought it was good at nearly everything, despite being inept at everything, and never made any sense. These qualities
were encapsulated perfectly by the HTTP-accept
header that it sent out with every request for a file on the Web. Basically speaking an HTTP-Accept
header is the browsers way of telling a Web server how well it can use files of a general or specific type. So to put it in plain English it ,might say something like I have 80% support for images in general but 100% for .jpg images
. The idea being that if the browser requests an image of a type that is not a .jpg and the server sees from the header that it works better with .jpg images, then the server has the opportunity to offer the same image in a .jpg format if there's one available. MSIE 6 however, lists the files it can use and how well it should be able to use them, but then adds a bit of a twist. After listing how well it suppports files of various types it then says it supports all types of files (including those that haven't been invented yet) 100%
Well thankfully MSIE 6 is long since dead and buried so I didn't have to work around its stupidity. HTML 5 probably isn't ,too far off and I see many similarities between the rush to that as I did with the rush to XHTML, but I can't say I've actually looked into it yet. So I've no idea if my MultiDoc class will be of any use to anyone else, but anyone that wants it is welcome to make use of it. I'll be using it to make the front page appear as an RSS feed to RSS readers. It's designed to be multi-purpose (hence the name), but I'll probably need to make a demo page to make it's use beyond simply converting XHTML to HTML a bit more obvious.
The PHP class file is MultiDoc, the XSLT file needed to transform the XHTML to HTML is xhtml-to-html.xslt, and for an example of the two being used together just have a peek at the main front page
Categories
- (X)HTML
- PHP
- XML