Home  >  Article  >  Backend Development  >  -关于PHP DomDocument 函数的有关问题

-关于PHP DomDocument 函数的有关问题

WBOY
WBOYOriginal
2016-06-13 11:48:38682browse

求助-关于PHP DomDocument 函数的问题

本帖最后由 Dana_Zhang 于 2014-02-17 00:26:13 编辑 大神们求助,如果别人给我传递的XML格式字符串,标签里面带有    或者  &  我new DomDocument 之后 使用 loadXML 函数载入的是报错  怎么办呀~~

补充一下:我使用的  PHP 版本是 5.2.17的 IIS: 是7.5 的版本  服务器是: windows server 2008 R2
------解决方案--------------------
用html_entity_decode(),然后再new DomDocument 
------解决方案--------------------
如果特殊字符 、& 不在 CDATA 标记中且没有转义,那么他就不是 XML
你可以用 loadHTML 方法载入
------解决方案--------------------
是不是转义问题
------解决方案--------------------
$dom  = new  DOMDocument ;
$dom -> loadXML ( '我是测试字符串。' );
if (! $dom ) {
echo 'Error while parsing the document' ;
exit;
}

$s = simplexml_import_dom ( $dom );

echo $s->text;


------解决方案--------------------
if ( file_exists ( 'test.xml' )) {
$xml = simplexml_load_file ( 'test.xml' );

echo $xml->text;
} else {
exit( 'Failed to open test.xml.' );
}


test.xml


我是测试字符串。

------解决方案--------------------
你首先确定你的xml是不是一个标准的xml,你可以去w3网站看看xml的规范,规范中不可以有这些特殊字符的。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn