ホームページ >バックエンド開発 >PHPチュートリアル >XML を解析できないとその解決方法

XML を解析できないとその解決方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBオリジナル
2016-06-13 13:33:581875ブラウズ

XML を解析できません。解決方法はありますか?

PHP コード
<!--

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');


実行後に次のエラーが見つかりました。
HTML コード
<!--

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 18
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: <person_siteurl>http://user.qzone.qq.com/1340477530#!app=2\&pos=1300412602</per in C:\wamp\www\test\a.php on line 18



$str1の「&」を削除すると正常になるのですがなぜでしょうか? 。解決策はありますか?ありがとう~~


-----解決策---------
$xml .= "t".''.htmlentities($str1).''."rn";
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。