[php-src] Issue #18878: DOMDocument::saveHTML() adds additional symbols before some UTF-8 characters in HTML
| From: | MurzNN | Date: | Thu, 19 Jun 2025 13:46:48 +0000 |
| Subject: | [php-src] Issue #18878: DOMDocument::saveHTML() adds additional symbols before some UTF-8 characters in HTML | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-250281@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/18878
Author: MurzNN
### Description
The following code:
```php
<?php
$html='<p>My Brand®</p>';
$dom = new \DOMDocument();
$dom->encoding = 'UTF-8';
$dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$result = $dom->saveHTML();
print($result);
```
Resulted in this output:
```
<p>My Brand®</p>
```
But I expected this output instead:
```
<p>My Brand®</p>
```
Or at least this:
```
<p>My Brand®</p>
```
The same issue is with other unicode characters, eg this:
```php
$html='<p>My ☆ Brand</p>';
```
output:
```
<p>My ☆ Brand</p>
```
Could you please explain why this happens, and how to fix this issue? Or maybe any workarounds?
### PHP Version
```plain
PHP 8.4.5 (cli) (built: Mar 17 2025 20:35:32) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.5, Copyright (c) Zend Technologies
with Zend OPcache v8.4.5, Copyright (c), by Zend Technologies
```
### Operating System
Ubuntu 25.04