Apple_Exporter\Components\Component::clean_html PHP Method

clean_html() protected static method

Use PHP's HTML parser to generate valid HTML out of potentially broken input.
protected static clean_html ( string $html ) : string
$html string
return string
    protected static function clean_html($html)
    {
        // Because PHP's DomDocument doesn't like HTML5 tags, ignore errors.
        $dom = new \DOMDocument();
        libxml_use_internal_errors(true);
        $dom->loadHTML('<?xml encoding="utf-8" ?>' . $html);
        libxml_clear_errors(true);
        // Find the first-level nodes of the body tag.
        $element = $dom->getElementsByTagName('body')->item(0)->childNodes->item(0);
        $html = $dom->saveHTML($element);
        return preg_replace('#<[^/>][^>]*></[^>]+>#', '', $html);
    }