I'm currently working on a load of PHP to make my website show as XHTML with an application/xhtml+xml content-type to non-shitty browsers (Firefox, Opera, Safari) and as HTML with a text/html content-type to shitty browsers (Internet Explorer).
At this point I'm mostly done, but I've got one more minor issue that I want fix.
The code in both versions of the page has trailing slashes in some tags as is correct for XHTML, but I want to change that in the HTML version so "<br />" becomes "<br>".
This is a very minor thing, but I'm fairly certain it can be done in PHP and would to do so.
Name:
Anonymous2007-03-17 23:13 ID:yT9DFLan
I don't understand why you'd want to do that. IE ignores standards and just does whatever the fuck it feels like doing, and you go out of your way to send it something that both renders correctly and validates?
Standards exist so that multiple applications can work with the same data. Since you're only sending out your data to IE, there's no reason to use standards.
Name:
Anonymous2007-03-18 0:13 ID:8GXqMhMB
strict xhtml is a gigantic waste of time
failing on any parsing error was a gigantic design mistake
gigantic
Also, technically, I'm not sending the HTML version specifically to Internet Explorer. I'm sending it to any user agent that doesn't say it can handle application/xhtml+xml, so it's a universal fall-back and should really use standards.
What I do is: if(isset($_SERVER['HTTP_ACCEPT']) && stripos($_SERVER['HTTP_ACCEPT'], "application/xhtml+xml") !== false) {
define('XML', '<?xml version="1.0" encoding="' . charset . '" ?>' . "\n");
define('doctype', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" ' .
'"'" target="_blank">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';);
define('contentType', "application/xhtml+xml; charset=".charset);
} else {
define('XML', "");
define('doctype','<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ' .
'"'" target="_blank">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';);
define('contentType', 'text/html; charset='.charset);
}
header("Content-Type: " . contentType);
The constants is then later used in this: <?php
return XML . doctype .
I have been sitting here for the past hour trying various combinations of that code and have so far only managed to get the DOCTYPE at the bottom of the page in HTML version. No combination of that code (or any code whatsoever) has so far gotten me what I actually want.
Does anyone have any idea how the fuck to actually do what I want?
Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.8.1.2) Gecko/20070220 Firefox/2.0.0.2
I'd rather not be doing this. I really would. But if I'm going to serve HTML 4.01 Strict to IE and some other browsers no one cares about, I'd rather do it right.
Why do you need to convert the tags to HTML for IE. Just serve the XHTML with a text/html content-type to IE. Also make sure the doctype is on the first line, so IE uses the standards compliance mode instead of quirks mode.
Well I don't need to convert the tags, but I have loads of time to waste and I know it'll bug me forever if I never manage to do this since I know it MUST be possible.
Most people would be able to apply this fix to the whole site and forget about it (since I've confirmed it works perfectly well) but I'm weird and obsessive.
Name:
Anonymous2007-03-18 20:25 ID:OP7PaOG7
make sure you change stuff like '<textarea ... />' to '<textarea ...></textarea>', but change stuff like '<br/>' to just '<br>'...
I'm 99.99% certain that all of my current pages can be made into HTML 4.01 Strict just by changing " />" to ">", and I can make special exceptions for any future cases or stuff I missed.
Name:
Anonymous2007-03-19 7:37 ID:CHTMT3uD
if you're going to produce actual validating HTML 4, why not just send HTML to all browsers? XHTML isn't some kind of magical more powerful upgrade to HTML, it's just another stupid standard written for people who can only understand the concept of brain-dead XML-style parsers.