note 129768 added to class.domdocument
| From: | devour@php.net | Date: | Wed, 25 Sep 2024 04:46:46 +0000 |
| Subject: | note 129768 added to class.domdocument | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221551@lists.php.net to get a copy of this message | ||
While DOMDocument can technically be used to parse HTML, it is not ideal for HTML documents and is
better suited for processing well-formed XML. One of the primary issues with using DOMDocument for
HTML is its strict handling of special characters, such as the ampersand (&).
DOMDocument requires that ampersands be escaped as &, which is in line with XML standards
but can be counterintuitive for handling real-world HTML, where raw & characters are commonly
found, especially in URLs and text. This behavior stems from the underlying XML-based parser
(libxml), which treats HTML with the same strictness as XML.
This problem has been reported as far back as 2001, yet the same parsing errors continue to occur
when using DOMDocument on HTML documents today.
A common workaround developers use is to suppress the error reporting from DOMDocument, particularly
when parsing errors like unescaped ampersands occur. However, suppressing these errors is not
recommended, especially in production environments, as it can hide important issues and pose
potential security risks. Ignoring or suppressing errors can leave warnings unnoticed, which may
result in vulnerabilities if not properly addressed.
For these reasons, it's advisable to use DOMDocument primarily for XML documents, or to
consider more appropriate libraries when working with HTML to avoid these issues.
theCoder / MV
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 104.28.225.130)
----
Manual Page -- https://php.net/manual/en/class.domdocument.php
Edit -- https://main.php.net/note/edit/129768
Del: integrated -- https://main.php.net/note/delete/129768/integrated
Del: useless -- https://main.php.net/note/delete/129768/useless
Del: bad code -- https://main.php.net/note/delete/129768/bad+code
Del: spam -- https://main.php.net/note/delete/129768/spam
Del: non-english -- https://main.php.net/note/delete/129768/non-english
Del: in docs -- https://main.php.net/note/delete/129768/in+docs
Del: other reasons-- https://main.php.net/note/delete/129768
Reject -- https://main.php.net/note/reject/129768
Search -- https://main.php.net/manage/user-notes.php