我正在尝试从链接解析 RSS 提要。这是我的代码:
$content = file_get_contents($this->feed);
print_r($content);
$rss = new SimpleXmlElement($content);
print_r($rss);
$rss_split = array();
/* foreach ($rss->channel->item as $item) {
$title = (string) $item->title; // Title
$link = (string) $item->link; // Url Link
$description = (string) $item->description; //Description
$rss_split[] = '<div><a href="' . $link . '" target="_blank" title="" >' . $title . ' </a><hr></div>';
}*/
完整的 XML 正在从这里下载: http: //devilsworkshop.org/feed/
下面是一个摘录来说明结构:
<item>
<title>Windows 8 Appstore resembles a ghost town</title>
<link>http://devilsworkshop.org/windows-appstore-resembles-ghost-town/</link>
<comments>http://devilsworkshop.org/windows-appstore-resembles-ghost-town/#comments</comments>
<pubDate>Tue, 18 Sep 2012 05:30:22 +0000</pubDate>
<dc:creator>Vibin</dc:creator>
<category><![CDATA[Analysis]]></category>
<category><![CDATA[Windows 8]]></category>
<guid isPermaLink="false">http://devilsworkshop.org/?p=62284</guid>
<description><![CDATA[<p>Microsoft is all set to release Windows 8 for public in the coming weeks. Apparently, the biggest change in Windows 8 seems to be the Metro UI (I know it’s no more called Metro, but let’s keep it like that [...]</p><p>--
This Post <a href="http://devilsworkshop.org/windows-appstore-resembles-ghost-town/">Windows 8 Appstore resembles a ghost town</a> is Published on <a href="http://devilsworkshop.org">Devils Workshop</a> .
</p><h3>Related posts:</h3><ul>
<li><a href='http://devilsworkshop.org/googles-new-look-resembles-yahoo-search/' rel='bookmark' title='Google’s new look resembles Yahoo Search'>Google’s new look resembles Yahoo Search</a></li>
</ul>]]></description>
<content:encoded><![CDATA[<p>Microsoft is all set to release Windows 8 for public in the coming weeks. Apparently, the biggest change in Windows 8 seems to be the Metro UI (I know it’s no more called Metro, but let’s keep it like that for simplicity) and apps.</p>
<ul>
<h2>Apps are less advanced</h2>
<p>Metro is great on tablets, but on desktop, it looks like an OS with dumbed down apps. Take Skitch for example, it is an app for taking and editing screenshots and was previously a Mac-only app but recently came to Windows 8. Just compare these two apps and you’ll know what I meant.</p>
<p>Here’s how Skitch looks in Windows 8:</p>
<p><a href="http://devilsworkshop.org/files/2012/09/SkitchinWindows8.png"><img style=' display: block; margin-right: auto; margin-left: auto;' class="aligncenter size-full wp-image-62302" title="SkitchinWindows8" src="http://devilsworkshop.org/files/2012/09/SkitchinWindows8.png" alt="" width="740" height="570" /></a></p>
<p>And now, this is the Mac version of Skitch:</p>
<p><a href="http://devilsworkshop.org/files/2012/09/SkitchinMac.png"><img style=' display: block; margin-right: auto; margin-left: auto;' class="aligncenter size-full wp-image-62301" title="SkitchinMac" src="http://devilsworkshop.org/files/2012/09/SkitchinMac.png" alt="" width="671" height="575" /></a></p>
<p>Another example can be Newsmix, an app which will let you read stuff that matters to you – in a Magazine layout. Apparently, this app is a fail for someone like me who subscribe to 50+ blogs.</p>
<p><a href="http://devilsworkshop.org/files/2012/09/NewsmixinWindows8.png"><img style=' display: block; margin-right: auto; margin-left: auto;' class="aligncenter size-large wp-image-62305" title="NewsMix in Windows 8" src="http://devilsworkshop.org/files/2012/09/NewsmixinWindows8-1024x640.png" alt="news-mix-windows-8" width="620" height="387" /></a><br />
Sure, it will be great on a Windows slate, but not really on a PC/laptop.</p>
<li><a href='http://devilsworkshop.org/how-to-enable-hibernate-option-in-windows-vistawindows-7/' rel='bookmark' title='How to enable Hibernate Option in Windows Vista/Windows 7'>How to enable Hibernate Option in Windows Vista/Windows 7</a></li>
<li><a href='http://devilsworkshop.org/windows-store/' rel='bookmark' title='Microsoft to Introduce Windows Store with Windows 8 Platform'>Microsoft to Introduce Windows Store with Windows 8 Platform</a></li>
</ul>]]>
</content:encoded>
<wfw:commentRss>http://devilsworkshop.org/windows-appstore-resembles-ghost-town/feed/</wfw:commentRss>
<slash:comments>0</slash:comments>
</item>
当我打印$content
时,它会显示content:encoded
标签中的图像。但是打印$rss
根本没有显示该标签,并且描述标签也显示了SimpleXMLElement Object()
。
我想解析两个标签。我在哪里做错了?