note 74555 deleted from ref.tidy by nlopess
| From: | nlopess@php.net | Date: | Tue, 01 May 2007 13:31:55 +0000 |
| Subject: | note 74555 deleted from ref.tidy by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126027@lists.php.net to get a copy of this message | ||
Note Submitter: Gusts Kaksis
----
This is an example of how-to prepare correct HTML for browsers that do not understand this fancy
thing.
Input: XHTML
Output: HTML (IE6, IE7), XHTML (others)
<?php
class XHTMLOut {
public $type = 'application/xhtml+xml';
public function __construct(){
if (strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')>0){;
$this->type = 'text/html';
header ('Content-type: '.$this->type);
ob_start();
} else {
header ('Content-type: '.$this->type);
echo '<?xml version="1.0"
encoding="utf-8"?>'."\n";
}
}
public function __destruct(){
if (strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')>0){
$str = ob_get_clean();
if (trim($str) != ''){
$config = array(
'doctype' => 'strict',
'indent' => true,
'input-xml' => false,
'output-xml' => false,
'wrap' => 0,
'output-html' => true);
$tidy = new tidy();
$tidy->parseString($str, $config, 'utf8');
$tidy->cleanRepair();
echo $tidy;
}
}
}
}
$out = new XHTMLOut();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en" lang="en">
<head>
<title>Firefox, Opera, Safari XHTML; IE6, IE7 HTML</title>
<meta http-equiv="Content-Type" content="<?php echo $out->type; ?>;
charset=utf-8" />
<meta http-equiv="content-language" content="en" />
</head>
<body>
<h1>Sample Title</h1>
<p>Sample Paragraph</p>
<p><img src="image.jpg" alt="image" title="sample"
/></p>
</body>
</html>