我正在尝试在RSS feed
中获取远程PHP array
内容并在其上执行一些操作。
我正在使用simplexml_load_file
将RSS
转换为Array
e.g。
<?php
$raw_array = simplexml_load_file('https://kickass.to/new/rss/');
print_r($raw_array);
?>
给出输出
SimpleXMLElement Object
(
[@attributes] => Array
(
[version] => 2.0
)
[channel] => SimpleXMLElement Object
(
[title] => Latest New Torrents RSS Feed - KickassTorrents
[link] => http://kat.cr/
[description] => Latest New Torrents RSS Feed
[item] => Array
(
[0] => SimpleXMLElement Object
(
[title] => title
[category] => category
[author] => http://kat.cr/user/author/
[link] => http://kat.cr/link.html
[guid] => http://kat.cr/link.html
[pubDate] => Mon, 18 May 2015 16:02:48 +0000
[enclosure] => SimpleXMLElement Object
(
[@attributes] => Array
(
[url] => http://torcache.net/torrent/hash.torrent
[length] => 83475908
[type] => application/x-bittorrent
)
)
)
但是当我直接进入RSS FEED并查看源代码时,会显示。
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:torrent="http://xmlns.ezrss.it/0.1/">
<channel>
<title>Latest New Torrents RSS Feed - KickassTorrents</title>
<link>http://kat.cr/</link>
<description>Latest New Torrents RSS Feed</description>
<item>
<title>titletitletitle</title>
<category>category- Video</category>
<author>http://kat.cr/user/author/</author> <link>http://kat.cr/link.html</link>
<guid>http://kat.cr/guid.html</guid>
<pubDate>Mon, 18 May 2015 15:36:42 +0000</pubDate>
<torrent:contentLength>125153743</torrent:contentLength>
<torrent:infoHash>212E859FB1BAFEA38BAB91BF3D94BB0DBB0ABFE4</torrent:infoHash>
<torrent:magnetURI><![CDATA[magnet:?xt=urn:btih:212E859FB1BAFEA38BAB91BF3D94BB0DBB0ABFE4&dn=titletitle=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce]]></torrent:magnetURI>
<torrent:seeds>0</torrent:seeds>
<torrent:peers>0</torrent:peers>
<torrent:verified>1</torrent:verified>
<torrent:fileName>fileName.torrent</torrent:fileName>
<enclosure url="http://torcache.net/torrent/212E859FB1BAFEA38BAB91BF3D94BB0DBB0ABFE4.torrent?title=[kat.cr]the.art.of.cocksucking.pir.te" length="125153743" type="application/x-bittorrent" />
</item>
所以当我使用simplexml_load_file
并不是所有子项/元素都被解析/获取时,它会丢失这些项目
<torrent:contentLength>125153743</torrent:contentLength>
<torrent:infoHash>212E859FB1BAFEA38BAB91BF3D94BB0DBB0ABFE4</torrent:infoHash>
<torrent:magnetURI><![CDATA[magnet:?xt=urn:btih:212E859FB1BAFEA38BAB91BF3D94BB0DBB0ABFE4&dn=titletitle=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce]]></torrent:magnetURI>
<torrent:seeds>0</torrent:seeds>
<torrent:peers>0</torrent:peers>
<torrent:verified>1</torrent:verified>
<torrent:fileName>fileName.torrent</torrent:fileName>
<torrent:fileName>wwe.payback.2015.ppv.hdtv.x264.champions.rarbg.torrent</torrent:fileName>
我怎样才能从这些元素中获取值?
参考:Parsing a XML file using simplexml_load_file return empty object
我已经通过指定命名空间从上面的url尝试了这个方法。
<?php
$raw_array = simplexml_load_file('https://kickass.to/new/rss/', null, null, 'torrent', true);
print_r($raw_array);
?>
但它给出了空对象
SimpleXMLElement Object
(
)
那么如何从这个RSS FEED中获取所有元素,我可以想到其他方式是使用PHP curl获取feed并使用preg_match来查找标签及其内部值,但这将是难看的修复。