Hi, Andrey.

This altered version of the script respects the Validator:

<?php


/*
    This script determines the preferred MIME type of a user agent
    and then delivers either application/xhtml+xml or text/html.
    Copyright (c) 2003 - 2004 Keystone Websites and Simon Jessey
*/


$charset = "utf-8";
$mime = "text/html";

function fix_code($buffer) {
    return (str_replace(" />", ">", $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_ACCE
PT"],$matches)) {
                 $html_q = $matches[1];
                        if((float)$xhtml_q >= (float)$html_q) {
                        $mime = "application/xhtml+xml";
   }
                }
        } else {
            $mime = "application/xhtml+xml";
                }
}

if(stristr($_SERVER["HTTP_USER_AGENT"],"WDG_Validator") ||
   stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator")) {
 $mime = "application/xhtml+xml";
}

if($mime == "application/xhtml+xml") {
 $doc_head = "<?xml version=\"1.0\" encoding=\"$charset\"?>\n";
 $doc_head = $doc_head."<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML
1.1//EN\"";
 $doc_head = $doc_head."
\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\";>\n";
 $doc_head = $doc_head."<html xmlns=\"http://www.w3.org/1999/xhtml\";
xml:lang=\"en\">\n\n";
 $doc_head = $doc_head."  <head>\n";
} else {
 ob_start("fix_code");
    $doc_head = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01
Transitional//EN\"";
    $doc_head = $doc_head." \"http://www.w3.org/TR/html4/loose.dtd\";>\n";
    $doc_head = $doc_head."<html lang=\"en\">\n\n";
    $doc_head = $doc_head."  <head>\n";
    $doc_head = $doc_head."    <meta http-equiv=\"content-type\"
content=\"$mime;charset=$charset\">\n";
}

header("Content-Type: $mime;charset=$charset");
header("Vary: Accept");

print $doc_head;

?>


Simon Jessey
----------------------------------
mail: [EMAIL PROTECTED]
web : http://jessey.net/blog/
work: http://keystonewebsites.com/




----- Original Message ----- 
From: "Andrey V. Stefanenko" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>

>
> I am try to adapt  technic of serving  the right MIME Type you may find at
> http://keystonewebsites.com/articles/mime_type.php
>
> Partially  "all" fine - at my page i am serving application/xhtml+xml with
> XHTML 1.1 Doctype to Mozilla based browsers  and text/html with XHTML 1.0
> Strict to others.
>
>
http://development.it.net.ua/lab/itdevelopment/itdevelopment/validator_mockery.php
>
> Work well - Mozilla get XHTML 1.1, IE6 get XHTML 1.0
>
> But W3C validator determine my source like XHTML 1.0 with "text/html"
> MIME-type

******************************************************
The discussion list for  http://webstandardsgroup.org/

 See http://webstandardsgroup.org/mail/guidelines.cfm
 for some hints on posting to the list & getting help
******************************************************

Reply via email to