解析XML并忽略特殊字符w / php

时间:2015-06-24 00:06:44

标签: php xml parsing simplexml

我正在尝试解析具有大量子属性的xml文件。

其中有一些特殊字符,我的php错误日志显示了这个

[23-Jun-2015 17:56:11 America/Denver] PHP Warning:  simplexml_load_file(): anime.xml:1: parser error : Start tag expected, '<' not found in /home/residez3/public_html/aresrelease/db/test.php on line 14
[23-Jun-2015 17:56:11 America/Denver] PHP Warning:  simplexml_load_file(): 1 in /home/residez3/public_html/aresrelease/db/test.php on line 14
[23-Jun-2015 17:56:11 America/Denver] PHP Warning:  simplexml_load_file(): ^ in /home/residez3/public_html/aresrelease/db/test.php on line 14
[23-Jun-2015 17:56:20 America/Denver] PHP Warning:  curl_setopt() expects parameter 2 to be long, string given in /home/residez3/public_html/aresrelease/db/test.php on line 6

XML https://pastebin.com/13hQAP2c

我试图从内部拉出某些子项和嵌套属性以显示在页面上。到目前为止,我只能显示整个xml文件,而不是抓住特定的孩子。

$url = "http://cdn.animenewsnetwork.com/encyclopedia/api.xml?anime=16252";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETRUNTRANSFER, ture);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, ture);
$opt = curl_exec($ch);

$handle = fopen("anime.xml", "wb");
fwrite($handle, $opt);
fclose($handle);

$xml = simplexml_load_file('anime.xml');

echo $xml->anime->attributes()->id;

1 个答案:

答案 0 :(得分:0)

我现在感到很愚蠢,我发现我的xml文件没有被写入。