XML无法解析&如何解决

WBOY
Release: 2016-06-13 10:19:17
Original
1336 people have browsed it

XML无法解析&,怎么解决啊

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$str1 = "http://user.qzone.qq.com/1340477530#!app=2&pos=1300412602";$xml = '<?xml version="1.0" encoding="utf-8"?>'."\r\n";$xml .= '<user>'."\r\n";$xml .= "\t".'<person_siteurl>'.$str1.'</person_siteurl>'."\r\n";$xml .= '</user>'."\r\n";$sxe = new SimpleXMLElement($xml);$sxe->asXML('test.xml');
Copy after login

运行后发现如下错误,
HTML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->arning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 3: parser error : EntityRef: expecting ';' in C:\wamp\www\test\a.php on line 18Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: <person_siteurl>http://user.qzone.qq.com/1340477530#!app=2\&pos=1300412602in C:\wamp\www\test\a.php on line 18</person_siteurl>
Copy after login


将$str1中的 "&" 去掉后就正常了,这是为什么啊。。有什么解决办法吗?谢谢~~


------解决方案--------------------
$xml .= "\t".''.htmlentities($str1).''."\r\n";
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template