note 78929 deleted from book.dom by cmb
| From: | cmb@php.net | Date: | Sun, 15 Sep 2019 18:11:22 +0000 |
| Subject: | note 78929 deleted from book.dom by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212229@lists.php.net to get a copy of this message | ||
Note Submitter: freyjkell at gmail dot com
----
In order to REALLY well handle XHTML entities with DOM, you can do following things:
1. Add this DOCTYPE to your documents
<!DOCTYPE xhtmlentities PUBLIC "-//W3C//ENTITIES XHTML Character Entities 1.0//EN"
"/xhtml11.ent">
2. Copy http://freyjkell.ovh.org/xhtml11.ent into
your document root.
3. In your PHP:
<?php
$dom=new DOMDocument();
$dom->load('file.xhtml',LIBXML_DTDLOAD); // NOT resolveExternals - it needs true
doctype, and includes crap code
// some DOM operations
$doctype=DOMImplementation::createDocumentType("html","-//W3C//DTD XHTML
1.1//EN","http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd");
// creating real doctype
$output=DOMImplementation::createDocument('','',$doctype);
$output->appendChild($output->importNode($dom->documentElement,true));
$output->encoding='utf-8';
$output=$output->saveXML();
$xhtml=preg_match(
'/application\/xhtml\+xml(?![+a-z])'.
'(;q=(0\.\d{1,3}|[01]))?/i',
$_SERVER['HTTP_ACCEPT'],$xhtml) &&
(isset($xhtml[2])?$xhtml[2]:1) > 0 ||
strpos($_SERVER["HTTP_USER_AGENT"],
"W3C_Validator")!==false ||
strpos($_SERVER["HTTP_USER_AGENT"],
"WebKit")!==false; // XHTML Content-Negotiation
header('Content-Type:
'.($xhtml?'application/xhtml+xml':'text/html').';
charset=utf-8');
print $output;
?>