note 125526 added to domdocument.loadhtml

From: Date: Fri, 20 Nov 2020 06:16:33 +0000
Subject: note 125526 added to domdocument.loadhtml
Groups: php.notes 
Request: Send a blank email to php-notes+get-215870@lists.php.net to get a copy of this message
If we are loading html5 tags such as <section>, <svg> there is following error: DOMDocument::loadHTML(): Tag section invalid in Entity We can disable standard libxml errors (and enable user error handling) using libxml_use_internal_errors(true); before loadHTML(); This is quite useful in phpunit custom assertions as given in following example (if using phpunit test cases): // Create a DOMDocument $dom = new DOMDocument(); // fix html5/svg errors libxml_use_internal_errors(true); // Load html $dom->loadHTML("<section></section>"); $htmlNodes = $dom->getElementsByTagName('section'); if ($htmlNodes->length == 0) { $this->assertFalse(TRUE); } else { $this->assertTrue(TRUE); } ---- Server IP: 45.112.84.4 Probable Submitter: 185.85.3.174 (proxied: 2402:8100:224d:c48:4db8:f4fa:e926:e5f3) ---- Manual Page -- http://php.net/manual/en/domdocument.loadhtml.php Edit -- https://master.php.net/note/edit/125526 Del: integrated -- https://master.php.net/note/delete/125526/integrated Del: useless -- https://master.php.net/note/delete/125526/useless Del: bad code -- https://master.php.net/note/delete/125526/bad+code Del: spam -- https://master.php.net/note/delete/125526/spam Del: non-english -- https://master.php.net/note/delete/125526/non-english Del: in docs -- https://master.php.net/note/delete/125526/in+docs Del: other reasons-- https://master.php.net/note/delete/125526 Reject -- https://master.php.net/note/reject/125526 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#215870) next »