Search code examples
phpxmlhtmlpurifier

HTMLPurifier without XML declaration


I am using HTMLPurifier on PHP to clean some dirty HTML, as follows:

$H=new HTMLPurifier()
$content_text_fixHTML = $H->purify($content_text);

Note: Omited encoding set up, because it is UTF-8

But, it will output the XML encoding declaration at the top.

<?xml encoding="utf-8" ?>

I do not want it. How do I prevent HTMLPurifier from adding it?

Thanks for your help in advance.


Solution

  • you need cut result string

    $n = strlen('<?xml encoding="utf-8" ?>');
    $content_text_fixHTML = substr($H->purify($content_text), $n);