0   /* vnav/labs/PHP/demoDTD.php -- demo version of doctype.php */
  1
  2   // user agents don't play nice
  3
  4   $agent = get_browser(null, true);
  5
  6   // and this one is the biggest bully in the schoolyard
  7
  8   $_IE = ($agent['browser'] == 'IE');
  9
 10   $media = array(
 11       'HTML'  => 'text/html',
 12       'XHTML' => 'application/xhtml+xml'
 13   );
 14
 15   $charset = 'UTF-8';     // unicode 8-bit character encoding
 16   $lang    = 'en-US';     // US english
 17
 18   function doctype($doc = 'xhtml', $type = 'strict', $ver = '1.1')    {
 19
 20       global $media, $media_type;     // these we share with head(), etc.
 21
 22       $doc  = strtoupper($doc);
 23       $type = strtolower($type);
 24
 25       $avail = 'PUBLIC';  // or SYSTEM, but we're not going there yet
 26
 27       // begin FPI
 28
 29       $ISO = '-';     // W3C is not ISO registered [or IETF for that matter]
 30       $OID = 'W3C';   // unique owner ID
 31       $PTC = 'DTD';   // the public text class
 32
 33       // as far as I know the PCL is always english
 34
 35       $PCL = 'EN';
 36       $xlang = 'en';  // this you may want to vary if you're in different locale
 37
 38       // DTDs are all under the Technical Reports branch @ W3C
 39
 40       $URI  = 'http://www.w3.org/TR/';
 41
 42       $doc_top  = '<html';    // what comes after the DOCTYPE of course
 43
 44       if ($doc == 'HTML') {
 45
 46           $top = $doc;
 47           $media_type = $media[$doc];
 48
 49           $PTD = $doc . ' 4.01';  // we're only supporting HTML 4.01 here
 50
 51           switch ($type)   {
 52
 53               case 'frameset':
 54
 55                   $PTD .= ' ' . ucfirst($type);
 56                   $URI .= 'html4/frameset.dtd';
 57                   break;
 58
 59               case 'transitional':
 60
 61                   $PTD .= ' ' . ucfirst($type);
 62                   $URI .= 'html4/loose.dtd';
 63                   break;
 64
 65               case 'strict':
 66               default:
 67
 68                   $URI .= 'html4/strict.dtd';
 69           }
 70           $doc_top .= '>';   // no namespaces here
 71       }
 72       else    {
 73
 74           // must be xhtml then, but catch typos
 75
 76           if ($doc != 'XHTML') $doc = 'XHTML';
 77
 78           $top = 'html';  // remember XML is lowercase
 79           $doc_top .= ' xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . $xlang . '"';
 80
 81           if ($ver == '1.1')  {
 82               $PTD = implode(' ', array($doc, $ver));
 83               $URI .= 'xhtml11/DTD/xhtml11.dtd';
 84           }
 85           else    {
 86               $PTD = implode(' ', array($doc, '1.0', ucfirst($type)));
 87               $URI .= 'xhtml1/DTD/xhtml1-' . $type . '.dtd';
 88
 89               // for backwards compatibilty
 90              
 91               $doc_top .= ' lang="' . $xlang . '"';
 92           }
 93
 94           $doc_top .= '>';    // close root XHTML tag
 95
 96           // return the correct media type header for this document,
 97           // but we should probably make sure the user-agent groks XML!
 98
 99           // hello W3C, anyone home? != 'Accept: application/xhtml+xml'
100
101           if (stristr($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator')) $media_type = $media['XHTML'];
102           else $media_type = (stristr($_SERVER['HTTP_ACCEPT'], $media['XHTML'])) ? $media['XHTML'] : $media['HTML'];
103
104           global $_IE, $charset, $lang;
105
106           // send HTTP header
107
108           header('Content-type: ' . $media_type . '; charset=' . $charset);
109
110           // send the XML declaration before the DOCTYPE, but this
111           // will put IE into quirks mode which we don't want
112
113           if (!$_IE) print '<?xml version="1.0" encoding="' . $charset . '"?>' . "\n";
114       }
115
116       $FPI = implode('//', array($ISO, $OID, $PTC . ' ' . $PTD, $PCL));
117
118       print <<<_DTD
119   <!DOCTYPE $top
120             $avail
121            "$FPI"
122            "$URI">
123   $doc_top
124
125   _DTD;
126 
127   } // doctype()