如<name>aa bb</name>
中间有这这格的实体符号时
会报出这种警告
( ! ) Warning: DOMDocument::load() [domdocument.load]: Entity 'nbsp' not defined in file:读取xml文档是这样子
$xml = new DOMDocument("1.0","UTF-8");
$xml->load('myxml.xml');
中间有这这格的实体符号时
会报出这种警告
( ! ) Warning: DOMDocument::load() [domdocument.load]: Entity 'nbsp' not defined in file:读取xml文档是这样子
$xml = new DOMDocument("1.0","UTF-8");
$xml->load('myxml.xml');
解决方案 »
- php 备份数据库的编码问题
- LAMP兄弟连[6月28-7月4日]期间在线讲座汇总
- 请教一个开源微薄
- cuteftp上传出错,‘连接被关闭;传输已放弃’
- 新手 PHP 使用TCPDF 询问一个功能 马上给分 !!!
- Job opportunity from Thouthtworks.
- 如何做在线文档编辑
- php报错,搭建egroupware,unexpected T_ARRAY, expecting '&' or T_VARIABLE
- eval($O00O0O(解密出来乱码怎么处理
- rabbitmq 连接数量一直增加
- discuz 将mysql换成DB2
- 用Snoopy类给THINKPHP框架的网站远程POST数据 令牌验证总是为真?
<?php
$str = <<<XML
<?xml version="1.0" encoding="iso-8859-1"?>
<div>This is a non-breaking space.</div>
XML;$dd1 = new DOMDocument();
$dd1->loadXML($str);echo $dd1->saveXML();
?>Given the above code, PHP will issue a Warning about the entity 'nbsp' not being properly declared. Also, the call to saveXML() will return nothing but a trimmed-down version of the original processing instruction...everything else is gone, and all because of the undeclared entity.Instead, explicitly declare the entity first:
<?php
$str = <<<XML
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE root [
<!ENTITY nbsp " ">
]>
<div>This is a non-breaking space.</div>
XML;$dd2 = new DOMDocument();
$dd2->loadXML($str);echo $dd2->saveXML();
?>Since the 'nbsp' entity is defined in the DOCTYPE, PHP no longer issues that Warning; the string is now well-formed, and loadXML() understands it perfectly.You can also use references to external DTDs in the same way (e.g., <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">), which is particularly important if you need to do this for many different documents with many different possible entities.Also, as a sidenote...entity references created by createEntityReference() do not need this kind of explicit declaration.
thanks ZT_king