简体   繁体   中英

Encoding problem in DOMDocument in php

When you do this:

$d = new DOMDocument();
$e = new DOMElement('myelement', 'hi   bye');
$d->appendChild($e);
$d->loadXML($d->saveXML());

..you get the following error:

PHP Warning:  DOMDocument::loadXML(): Entity 'nbsp' not defined in Entity, line: 2 in php shell code on line 1

Why does this happen? Shoudn't libxml handle entities correctly?

Use loadHTML() instead since this entity is a HTML entity and not a generic XML entity.

http://www.php.net/manual/en/domdocument.loadxml.php#89212

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM