Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

XHTML to HTML

Name: Anonymous 2007-03-17 22:26 ID:mmTvIK73

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: Anonymous 2007-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: Anonymous 2007-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

Name: Anonymous 2007-03-18 0:22 ID:g95BiQ5+

>>2
I'm very pedantic.

Name: Anonymous 2007-03-18 0:31 ID:g95BiQ5+

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.

Name: Anonymous 2007-03-18 2:18 ID:wWFL2CWI

>>1
str_replace(" />", ">", $page); // ?

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 .

'
<html xmlns="http://www.w3.org/1999/xhtml">;
<head>
' . (XML ===""? '    <meta http-equiv="Content-Type" content="'.contentType.'" />' . "\n" : "") .
'    <title>'. htmlspecialchars(siteDesc . (defined("location") ? ": " . location : "")) .'</title>
    <style type="text/css">
        @import url(' . SKIN_dir . 'style.css);
    </style>
</head>

<body>
';
?>

Name: Anonymous 2007-03-18 2:45 ID:g95BiQ5+

That didn't seem to work. The code as I have it right now goes as follows:

<?php
if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ||
    stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator")     ||
    stristr($_SERVER["HTTP_USER_AGENT"],"W3C_CSS_Validator") ||
    stristr($_SERVER["HTTP_USER_AGENT"],"WDG_Validator")) {
    header("Content-type: application/xhtml+xml; charset=utf-8");
    echo("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\n    \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n");                    
}
else {
    header("Content-type: text/html; charset=utf-8");
    echo("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n    \"http://www.w3.org/TR/html4/strict.dtd\">\n<html lang=\"en\">\n");
    str_replace(" />", ">", $page);
}
?>

Name: Anonymous 2007-03-18 4:16 ID:wWFL2CWI

>>7
Sorry, my code did not foresee the error-id 10-T, totally my fault.

At the top of the page you put «ob_start();», before aaaaany output.

And at the bottom of the page you put «$page=ob_get_contents();ob_end_clean();», then that code of yours, and then «echo $page;».

« and » is quotation marks. Feel free to include them in your code but be prepared to get a few error messages if you do.

Name: Anonymous 2007-03-18 6:31 ID:Heaven

ID10T

Name: Anonymous 2007-03-18 11:18 ID:d0grBpQ0

« and » is quotation marks
Fuck off Frenchie.

Name: Anonymous 2007-03-18 11:41 ID:wWFL2CWI

>>10
Norwegian.

Name: Anonymous 2007-03-18 12:39 ID:Js6OpTxx

>>11
German.

Name: Anonymous 2007-03-18 14:17 ID:Heaven

is quotation marks.
your english are good.

Name: Anonymous 2007-03-18 15:50 ID:QgQVNiOY

>>8

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?

Name: Anonymous 2007-03-18 17:21 ID:Js6OpTxx

>>14
www.opera.com

can't do XHTML with some shitty browser

Name: Anonymous 2007-03-18 17:55 ID:CY0pyVKF

NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM! NEWGROUNDS.COM!

Name: Anonymous 2007-03-18 18:58 ID:QgQVNiOY

>>15

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.

>>16

Eat shit and die.

Name: Anonymous 2007-03-18 19:10 ID:wXgXamZB

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.

Name: Anonymous 2007-03-18 19:14 ID:QgQVNiOY

>>18

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: Anonymous 2007-03-18 20:25 ID:OP7PaOG7

make sure you change stuff like '<textarea ... />' to '<textarea ...></textarea>', but change stuff like '<br/>' to just '<br>'...

Name: Anonymous 2007-03-18 20:50 ID:QgQVNiOY

>>21

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: Anonymous 2007-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.

Name: Anonymous 2007-10-02 16:56 ID:qhLY6LDc

WELCOME TO THE PAST BITCH, FUCKING BUMP.

Name: Anonymous 2007-10-03 5:59

One word, strict XHTML faggots, /> all over the source

Name: Anonymous 2010-12-06 9:30

Back to /b/, ``GNAA Faggot''

Name: Anonymous 2011-02-03 5:37

Name: Sgt.Kabuዽ螼kimanៀ 2012-05-28 23:38

Bringing /prog/ back to its people

Don't change these.
Name: Email:
Entire Thread Thread List