View Source

myMIME.php
  1. <?php
  2. $charset = "utf-8"; # iso-8859-1 OR utf-8
  3. $mime = "text/html";
  4.  
  5. # NOTE: To allow for q-values with one space (text/html; q=0.5),
  6. # use the following regex:
  7. # "/text\/html;[\ ]{0,1}q=([0-1]{0,1}\.\d{0,4})/i"
  8. if((isset($_SERVER["HTTP_ACCEPT"])) && (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml"))) {
  9.    if(preg_match("/application\/xhtml\+xml;q=([0-1]{0,1}\.\d{0,4})/i",$_SERVER["HTTP_ACCEPT"],$matches)) {
  10.       $xhtml_q = $matches[1];
  11.       if(preg_match("/text\/html;q=([0-1]{0,1}\.\d{0,4})/i",$_SERVER["HTTP_ACCEPT"],$matches)) {
  12.          $html_q = $matches[1];
  13.          if((float)$xhtml_q >= (float)$html_q)
  14.             $mime = "application/xhtml+xml";
  15.         }
  16.      }
  17.    else
  18.   $mime = "application/xhtml+xml";
  19.   }
  20.  
  21. # special check for the W3C_Validator
  22. # (allows IE page validation as XHTMLv1.1)
  23. # but still serves page for IE to "understand" (i.e. text/html)
  24. if (stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator")) {
  25.    $mime = "application/xhtml+xml";
  26.   }
  27.  
  28. # set the prolog_type according to the mime type which was determined
  29. if($mime == "application/xhtml+xml") {
  30.    $prolog_type  = '<?xml version="1.0" encoding="'.$charset.'" ?>'."\n";
  31.    $prolog_type .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" ';
  32. $prolog_type .= '"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'."\n";
  33.    $prolog_type .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">'."\n\n";
  34.   } else {
  35.    $prolog_type  = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"';
  36. $prolog_type .= '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n";
  37. $prolog_type .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n\n";
  38.  
  39.   }
  40.  
  41. # output the mime type and prolog type to your page
  42. header("Content-Type: $mime;charset=$charset");
  43. header("Vary: Accept");
  44. print $prolog_type;
  45.  
  46. ?>
  47.  
Parsed in 0.024 seconds