【问题标题】:Parsing XML and ignoring special characters w/ php使用 php 解析 XML 并忽略特殊字符
【发布时间】:2015-09-10 00:04:03
【问题描述】:

我正在尝试解析具有大量子属性的 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

XMLhttps://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;

【问题讨论】:

    标签: php xml parsing simplexml


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-21
      相关资源
      最近更新 更多