/home/wpollock1/public_html/PHP/mimetype.php

 1: <?php
 2: # This script from www.workingwith.me.uk/articles/scripting/mimetypes
 3: # Posted by Neil Crosby on April 17, 2004 08:27 PM
 4: # and modified by Wayne Pollock 6/2007 (according to the various
 5: # follow-up postings.)
 6: 
 7: $charset = "utf-8";
 8: $mime = "text/html";
 9: 
10: function fix_code ( $buffer )
11: {
12:    return (str_replace(" />", ">", $buffer));
13: }
14: 
15: if ( isset($_SERVER["HTTP_ACCEPT"])
16:      && stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml") )
17: {
18:    # if there's a Q value for "application/xhtml+xml" then also
19:    # retrieve the Q value for "text/html"
20:    if ( preg_match("/application\/xhtml\+xml;q=0(\.[1-9]+)/i",
21:                    $_SERVER["HTTP_ACCEPT"], $matches) )
22:    {
23:       $xhtml_q = $matches[1];
24:       if ( preg_match("/text\/html;q=0(\.[1-9]+)/i",
25:                       $_SERVER["HTTP_ACCEPT"], $matches) )
26:       {
27:          $html_q = $matches[1];
28:          # if the Q value for XHTML is greater than or equal to that
29:          # for HTML then use the "application/xhtml+xml" mimetype
30:          if ( $xhtml_q >= $html_q )
31:          {
32:             $mime = "application/xhtml+xml";
33:          }
34:       }
35:    # if there was no Q value, then just use the
36:    # "application/xhtml+xml" mimetype
37:    } else {
38:       $mime = "application/xhtml+xml";
39:    }
40: }
41: 
42: # special check for the W3C_Validator
43: if ( stristr($_SERVER["HTTP_USER_AGENT"], "W3C_Validator") )
44: {
45:    $mime = "application/xhtml+xml";
46: }
47: 
48: # set the prolog_type according to the mime type which was determined
49: if ( $mime == "application/xhtml+xml" )
50: {
51:    $prolog_type = "<?xml version='1.0' encoding='$charset' ?>\n";
52:    $prolog_type .= "      <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'\n";
53:    $prolog_type .= "      'http://www.w3.org/TR/xhtml11/DTD/xhtml11-strict.dtd'>\n";
54:    $prolog_type .= "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>\n";
55: } else {
56:    ob_start( "fix_code" );
57:    $prolog_type = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN'\n";
58:    $prolog_type .= "      'http://www.w3.org/TR/html4/strict.dtd'>\n";
59:    $prolog_type .= "<html lang='en'>\n";
60: }
61: 
62: # finally, output the mime type and prolog type
63: header( "Content-Type: $mime;charset=$charset" );
64: header( "Vary: Accept" );
65: print $prolog_type;
66: ?>