How do I ignore CDATA tags?

I am trying to make an html parser but when I load the html I get warnings like this

Warning: DOMDocument :: loadHTML () [domdocument.loadhtml]: Invalid char in CDATA 0x1C in Entity, line: 1302

Here is the code I am using

class Parser
public $url=null;
public $html=null;
public $tidy=null;
public $head=null;
public $head_xpath=null;

function __construct($url){
    $this->head=new DOMDocument();
    $this->head_xpath= new DOMXPath($this->head);


$x=new Parser("");


I searched and found the LIBXML_NOCDATA constant, but I don't know how to set it. So how could I ignore CDATA completely?


source to share

1 answer

$this->html = preg_replace('~//\s*?<!\[CDATA\[\s*|\s*//\]\]>~', '', $this->html);


should work but haven't tested it.



All Articles