Welcome Guest, Not a member yet? Register   Sign In
jQuery - Stripping self-closing tags
#2

[eluser]Kyle Johnson[/eluser]
***UPDATE***

Fixed it.

Found a few interesting points regarding serving the page with the correct MIME type, as the browser determines what to parse the JavaScript as.
http://keystonewebsites.com/articles/mime_type.php

So by following the advice there, my tags are now properly closed according to the supplied standard.

So by using this in a file:
Code:
<?php
$charset = "iso-8859-1";
$mime = "text/html";
function fix_code($buffer) {
return (preg_replace("!\s*/>!", ">", $buffer));
}
if(stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")) {
        if(preg_match("/application\/xhtml\+xml;q=([01]|0\.\d{1,3}|1\.0)/i",$_SERVER["HTTP_ACCEPT"],$matches)) {
            $xhtml_q = $matches[1];
                if(preg_match("/text\/html;q=q=([01]|0\.\d{1,3}|1\.0)/i",$_SERVER["HTTP_ACCEPT"],$matches)) {
                    $html_q = $matches[1];
                        if((float)$xhtml_q >= (float)$html_q) {
                        $mime = "application/xhtml+xml";
            }
                }
        } else {
               $mime = "application/xhtml+xml";
                }
}
if($mime == "application/xhtml+xml") {
    $prolog_type = "&lt;?xml version=\"1.0\" encoding=\"$charset\" ?&gt;\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n&lt;html &gt;\n";
} else {
    ob_start("fix_code");
        $prolog_type = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n&lt;html lang=\"en\"&gt;\n";
}
header("Content-Type: $mime;charset=$charset");
header("Vary: Accept");
print $prolog_type;
?&gt;

And then importing it:
Code:
&lt;?php include("/path/filename.php"); ?&gt;
&lt;head&gt;
&lt;title&gt;Test page&lt;/title&gt;
...

However, the above doesn't appear to work when using w3.org's validator as it tries to parse it using HTML 4.. This makes older browsers capable of generating the page (I think).

However, adding the following code directly seems to bypass that problem:
Code:
&lt;?php echo "&lt;?xml version=\"1.0\" encoding=\"iso-8859-1\" ?&gt;\n"; ?&gt;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;title&gt;Test page&lt;/title&gt;
...


Messages In This Thread
jQuery - Stripping self-closing tags - by El Forum - 06-23-2009, 03:48 PM
jQuery - Stripping self-closing tags - by El Forum - 06-23-2009, 04:10 PM



Theme © iAndrew 2016 - Forum software by © MyBB