function repair_html
Search API
| 7.x misc.inc | repair_html($html) |
2 calls to repair_html()
- filter_markup in includes/
misc.inc - Filter string with possible HTML, allowing only certain tags, and removing dangerous attributes.
- misc.inc in includes/
misc.inc - This file contains misc functions for FlightPath
File
- includes/
misc.inc, line 1149 - This file contains misc functions for FlightPath
Code
function repair_html($html) {
// hide DOM parsing errors
libxml_use_internal_errors(true);
libxml_clear_errors();
// load the possibly malformed HTML into a DOMDocument
$dom = new DOMDocument();
$dom->recover = true;
$rnd = mt_rand(9, 9999) . time(); // just in case we have something else with ID "repair"
$dom->loadHTML('<?xml encoding="UTF-8"><body id="repair' . $rnd . '">' . $html . '</body>'); // input UTF-8
// copy the document content into a new document
$doc = new DOMDocument();
foreach ($dom->getElementById('repair' . $rnd)->childNodes as $child) {
$doc->appendChild($doc->importNode($child, true));
}
// output the new document as HTML
$doc->encoding = 'UTF-8'; // output UTF-8
$doc->formatOutput = false;
return trim($doc->saveHTML());
}
