Req #47875 [Ver]: No option to set HTML input encoding
| From: | nielsdos@php.net | Date: | Wed, 04 Oct 2023 20:02:05 +0000 |
| Subject: | Req #47875 [Ver]: No option to set HTML input encoding | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-245499@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=47875&edit=1
ID: 47875
Updated by: nielsdos@php.net
Reported by: thomas dot koch at ymc dot ch
Summary: No option to set HTML input encoding
Status: Verified
Type: Feature/Change Request
Package: DOM XML related
Operating System: Debian Lenny
PHP Version: 5.2.9
Block user comment: N
Private report: N
New Comment:
This will be fixed when this RFC is accepted & implemented: https://wiki.php.net/rfc/domdocument_html5_parser
Previous Comments:
------------------------------------------------------------------------
[2023-09-20 17:54:11] markokarjalainen at kolumbus dot fi
Any plan to fix this real old bug?
1. loadHTML should be always UTF-8 as default, like DOMDocument self is.
2. If user give charset in DOMDocument::__construct(), then loadHTML should to be use it.
3. If imported HTML contains charset, then use it.
Maybe this kind of change not broke the world?
------------------------------------------------------------------------
[2020-10-23 15:22:50] cmb@php.net
Not a solution, but likely a viable workaround would be prepending
the HTML string with a BOM ("\xef\xbb\xbf" for UTF-8), see
<https://3v4l.org/ArhNb>.
------------------------------------------------------------------------
[2018-07-22 18:36:11] anrdaemon at freemail dot ru
Prefixing does not work.
The default input encoding of DOMDocument is IS-8859-1 contrary to the documentation that says the
input should be UTF-8 encoded.
If you prefix your document with "<?xml â¦", it will change mode to UTF-8
regardless of encoding specified in the XML declaration, and mangle the declaration itself.
https://3v4l.org/HL5It
In short, DOMDocument is largely unusable for HTML, only well-formed XML with explicit declaration
gives you a small hope of success.
------------------------------------------------------------------------
[2015-12-22 21:19:12] nathan dot renniewaldock at gmail dot com
This really does need to be supported. Though libxml2 is partly to blame for ignoring <meta
charset="utf-8">
For now, workaround is to prefix the HTML with either
<?xml version="1.0" encoding="UTF-8"?>
or
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
------------------------------------------------------------------------
[2015-07-10 15:55:59] cmb@php.net
Related To: Bug #49705
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=47875
--
Edit this bug report at https://bugs.php.net/bug.php?id=47875&edit=1