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

时间:2021-09-18 04:26:18

I am trying to parse through an xml files that has a ton of child attributes.

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

There are some special characters in it and my php errorlog shows this

它中有一些特殊字符,我的php errorlog显示了这一点

[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

I am trying to pull certain child and nested attributes from within to display on a page. So far I am only able to display the whole xml file and not grab a specific child.

我试图从内部拉出某些子和嵌套属性以显示在页面上。到目前为止,我只能显示整个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 个解决方案

#1


0  

I feel really dumb now, I figured out that my xml file wasn't being written to.

我觉得现在真的很蠢,我发现我的xml文件没有被写入。

#1


0  

I feel really dumb now, I figured out that my xml file wasn't being written to.

我觉得现在真的很蠢,我发现我的xml文件没有被写入。