简体   繁体   English

php 中的 DOMDocument 中的编码问题

[英]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? libxml不应该正确处理实体吗?

Use loadHTML() instead since this entity is a HTML entity and not a generic XML entity.请改用loadHTML() ,因为此实体是 HTML 实体,而不是通用 XML 实体。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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