我试图在PHP文件中显示来自rss feed的图像。
php文件非常简单,而且不是很多。
rss feed也来自天空新闻。我得到的php文件将提取我需要的所有信息并显示它们但我不完全确定如何显示图像。
这是我的PHP代码:
<?php
$rss = simplexml_load_file('http://www.skysports.com/rss/0,20514,11959,00.xml');
echo '<h1>'. $rss->channel->title . '</h1>';
foreach ($rss->channel->item as $item) {
echo '<h2><a href="'. $item->link .'">' . $item->title . "</a></h2>";
echo "<p>" . $item->pubDate . "</p>";
echo "<p>" . $item->description . "</p>";
}
?>
这是xml rss feed的结构:
<?xml version="1.0" encoding="iso-8859-1" ?>
<?xml-stylesheet title="XSL_formatting" type="text/xsl" href="http://www.skysports.com/styles/rss-render/0,26674,,00.xsl"?>
<rss version="2.0">
<channel>
<title>Sky Sports | Football News</title>
<link>http://www.skysports.com</link>
<description>Europa League News</description>
<language>en-gb</language>
<lastBuildDate>Wed, 27 Mar 2013 18:20:18 GMT</lastBuildDate>
<copyright>Copyright 2013, BSKYB. All Rights Reserved.</copyright>
<category>Football</category>
<image>
<title>Sky Sports</title>
<url>http://www.skysports.com/Images/skysports/site/ss-logo-07.gif</url>
<link>http://www.skysports.com</link>
</image>
<ttl>120</ttl>
<item><title><![CDATA[Cisse eyes glory]]></title><description><![CDATA[Papiss Cisse is confident that Newcastle's season can finish in glory.]]></description><link>http://www1.skysports.com/football/news/11959/8601723/</link><guid isPermaLink="false">11959_8601723</guid><pubDate>Wed, 27 Mar 2013 18:12:36 GMT</pubDate><category>News Story</category><enclosure type="image/jpg" url="http://img.skysports.com/13/02/128x67/Newcastle-v-Metalist-Kharkiv-Papiss-Cisse_2900940.jpg" length="123456" /></item>
<item><title><![CDATA[Chelsea clash moved to Moscow]]></title><description><![CDATA[UEFA has confirmed that Chelsea's Europa League quarter-final second-leg with Rubin Kazan has been moved to the Luzhniki Stadium in Moscow.]]></description><link>http://www1.skysports.com/football/news/11959/8580924/</link><guid isPermaLink="false">11959_8580924</guid><pubDate>Thu, 21 Mar 2013 10:43:18 GMT</pubDate><category>News Story</category><enclosure type="image/jpg" url="http://img.skysports.com/13/03/128x67/Rubin-Kazan-v-Levante-Jos-Rondon-Sergio-Balle_2915002.jpg" length="123456" /></item>
<item><title><![CDATA[UEFA opens Inter 'abuse' case]]></title><description><![CDATA[UEFA has announced that a disciplinary case is to be opened against Inter Milan, following reports of fans racially abusing Tottenham players during last Thursday's Europa League game at the San Siro.]]></description><link>http://www1.skysports.com/football/news/11959/8575656/</link><guid isPermaLink="false">11959_8575656</guid><pubDate>Mon, 18 Mar 2013 12:26:33 GMT</pubDate><category>News Story</category><enclosure type="image/jpg" url="http://img.skysports.com/13/03/128x67/Inter-Milan-v-Tottenham-Emmanuel-Adebayor_2915019.jpg" length="123456" /></item>
<item><title><![CDATA[Gallas wants racism reaction]]></title><description><![CDATA[Tottenham defender William Gallas says walking off the pitch is an understandable reaction to racist abuse and has called on UEFA to respond after chants marred Thursday's game with Inter Milan.]]></description><link>http://www1.skysports.com/football/news/11959/8569919/</link><guid isPermaLink="false">11959_8569919</guid><pubDate>Sat, 16 Mar 2013 11:09:25 GMT</pubDate><category>News Story</category><enclosure type="image/jpg" url="http://img.skysports.com/12/08/128x67/William-Gallas-Tottenham-vs-Valencia_2811170.jpg" length="123456" /></item>
<item><title><![CDATA[Spurs want tough UEFA stance]]></title><description><![CDATA[Tottenham Hotspur have told Sky Sports they want UEFA to 'make a stand' against racism after their players were abused at Inter Milan on Thursday.]]></description><link>http://www1.skysports.com/football/news/11959/8567989/</link><guid isPermaLink="false">11959_8567989</guid><pubDate>Fri, 15 Mar 2013 13:45:03 GMT</pubDate><category>News Story</category><enclosure type="image/jpg" url="http://img.skysports.com/13/03/128x67/Inter-Milan-v-Tottenham-Jake-Livermore-Antoni_2915000.jpg" length="123456" /></item>
<item><title><![CDATA[Pardew: Perfect Europa draw]]></title><description><![CDATA[Alan Pardew was delighted as Newcastle were drawn to face Benfica in the quarter-finals of this season's Europa League.]]></description><link>http://www1.skysports.com/football/news/11959/8567905/</link><guid isPermaLink="false">11959_8567905</guid><pubDate>Fri, 15 Mar 2013 13:18:54 GMT</pubDate><category>News Story</category><enclosure type="image/jpg" url="http://img.skysports.com/13/03/128x67/Alan-Pardew-Beard_2910689.jpg" length="123456" /></item>
<item><title><![CDATA[Bernstein slams Spurs abuse]]></title><description><![CDATA[Football Association chairman David Bernstein has condemned the racist abuse directed towards some Tottenham players in their Europa League game with Inter Milan on Thursday night.]]></description><link>http://www1.skysports.com/football/news/11959/8567723/</link><guid isPermaLink="false">11959_8567723</guid><pubDate>Fri, 15 Mar 2013 12:33:42 GMT</pubDate><category>News Story</category><enclosure type="image/jpg" url="http://img.skysports.com/12/09/128x67/Bernstein_2827663.jpg" length="123456" /></item>
<item><title><![CDATA[English trio are kept apart]]></title><description><![CDATA[The three Premier League clubs have been kept apart in the Europa League quarter-final draw.]]></description><link>http://www1.skysports.com/football/news/11959/8567594/</link><guid isPermaLink="false">11959_8567594</guid><pubDate>Fri, 15 Mar 2013 11:58:29 GMT</pubDate><category>News Story</category><enclosure type="image/jpg" url="http://img.skysports.com/12/12/128x67/trophy_2871143.jpg" length="123456" /></item>
<item><title><![CDATA[UEFA waits on Inter decision]]></title><description><![CDATA[UEFA has confirmed they do not expect to make a decision on Friday over whether to open a case against Inter Milan after some of their fans racially abused Tottenham players.]]></description><link>http://www1.skysports.com/football/news/11959/8567161/</link><guid isPermaLink="false">11959_8567161</guid><pubDate>Fri, 15 Mar 2013 09:55:55 GMT</pubDate><category>News Story</category><enclosure type="image/jpg" url="http://img.skysports.com/13/03/128x67/Inter-Milan-v-Tottenham-Emmanuel-Adebayor_2915019.jpg" length="123456" /></item>
<item><title><![CDATA[Pardew: Europa glory possible]]></title><description><![CDATA[Alan Pardew believes Newcastle United are capable of winning the Europa League after making their way into the quarter-finals.]]></description><link>http://www1.skysports.com/football/news/11959/8566927/</link><guid isPermaLink="false">11959_8566927</guid><pubDate>Fri, 15 Mar 2013 08:24:22 GMT</pubDate><category>News Story</category><enclosure type="image/jpg" url="http://img.skysports.com/13/03/128x67/Alan_2915255.jpg" length="123456" /></item>
<item><title><![CDATA[Benitez: Torres back on track]]></title><description><![CDATA[Chelsea interim manager Rafael Benitez believes Fernando Torres has fresh confidence, despite his penalty miss in the Europa League victory over Steaua Bucharest.]]></description><link>http://www1.skysports.com/football/news/11959/8566349/</link><guid isPermaLink="false">11959_8566349</guid><pubDate>Fri, 15 Mar 2013 00:06:25 GMT</pubDate><category>News Story</category><enclosure type="image/jpg" url="http://img.skysports.com/13/03/128x67/benitez_2915142.jpg" length="123456" /></item>
<item><title><![CDATA[Cech content with 'big win']]></title><description><![CDATA[Chelsea goalkeeper Petr Cech felt his side were always capable of seeing off Steaua Bucharest in the UEFA Europa League to advance to the quarter-finals but was relieved to get the job done.]]></description><link>http://www1.skysports.com/football/news/11959/8566291/</link><guid isPermaLink="false">11959_8566291</guid><pubDate>Thu, 14 Mar 2013 23:15:00 GMT</pubDate><category>News Story</category><enclosure type="image/jpg" url="http://img.skysports.com/13/02/128x67/Cech1_2904805.jpg" length="123456" /></item>
<item><title><![CDATA[Stramaccioni proud of Inter]]></title><description><![CDATA[Inter Milan head coach Andrea Stramaccioni hailed his side's monumental effort as they very nearly pulled off a shock triumph against Tottenham in the UEFA Europa League.]]></description><link>http://www1.skysports.com/football/news/11959/8566278/</link><guid isPermaLink="false">11959_8566278</guid><pubDate>Thu, 14 Mar 2013 23:01:16 GMT</pubDate><category>News Story</category><enclosure type="image/jpg" url="http://img.skysports.com/13/03/128x67/Inter-Milan-v-Tottenham-Andrea-Stramaccioni_2915006.jpg" length="123456" /></item>
<item><title><![CDATA[Pardew salutes super Cisse]]></title><description><![CDATA[Alan Pardew saluted more last-gasp heroics from Papiss Cisse after his dramatic lone goal against Anzhi Makhachkala sent Newcastle through to the Europa League quarter-finals.]]></description><link>http://www1.skysports.com/football/news/11959/8566265/</link><guid isPermaLink="false">11959_8566265</guid><pubDate>Thu, 14 Mar 2013 22:51:34 GMT</pubDate><category>News Story</category><enclosure type="image/jpg" url="http://img.skysports.com/13/03/128x67/Alan_2915255.jpg" length="123456" /></item>
<item><title><![CDATA[Lazio too strong for Stuttgart]]></title><description><![CDATA[Libor Kozak scored twice in the opening 10 minutes and completed a hat-trick late on as Lazio turned on the style behind closed doors to reach the Europa League quarter-finals.]]></description><link>http://www.skysports.com/football/match_report/0,19764,11065_3602531,00.html</link><guid isPermaLink="false">11959_8566244</guid><pubDate>Thu, 14 Mar 2013 22:38:58 GMT</pubDate><category>Report</category><enclosure type="image/jpg" url="http://img.skysports.com/13/03/128x67/Lazio-v-Stuttgart-Libor-Kozak-2_2915077.jpg" length="123456" /></item>
<item><title><![CDATA[AVB: UEFA will act on chants]]></title><description><![CDATA[Andre Villas-Boas expects UEFA to act after Inter Milan fans appeared to racially abuse Tottenham players as they fought back to reach the UEFA Europa League quarter-finals.]]></description><link>http://www1.skysports.com/football/news/11959/8566242/</link><guid isPermaLink="false">11959_8566242</guid><pubDate>Thu, 14 Mar 2013 22:37:49 GMT</pubDate><category>News Story</category><enclosure type="image/jpg" url="http://img.skysports.com/13/03/128x67/avb2_2915141.jpg" length="123456" /></item>
<item><title><![CDATA[Fenerbahce sneak past Plzen]]></title><description><![CDATA[Substitute Salih Ucan was the hero as Fenerbahce did enough to squeeze into the Europa League quarter-finals with a home draw against Viktoria Plzen.]]></description><link>http://www.skysports.com/football/match_report/0,19764,11065_3602528,00.html</link><guid isPermaLink="false">11959_8566227</guid><pubDate>Thu, 14 Mar 2013 22:25:04 GMT</pubDate><category>Report</category><enclosure type="image/jpg" url="http://img.skysports.com/13/02/128x67/Vladimir-Darida_2900876.jpg" length="123456" /></item>
<item><title><![CDATA[Benfica ease past Bordeaux]]></title><description><![CDATA[Benfica eased into the quarter-finals of the Europa League as they proved too strong for Bordeaux in the south of France.]]></description><link>http://www.skysports.com/football/match_report/0,19764,11065_3602529,00.html</link><guid isPermaLink="false">11959_8566219</guid><pubDate>Thu, 14 Mar 2013 22:21:16 GMT</pubDate><category>Report</category><enclosure type="image/jpg" url="http://img.skysports.com/11/04/128x67/Jardelcelebrates_2590756.jpg" length="123456" /></item>
<item><title><![CDATA[Cisse stuns Anzhi to win it]]></title><description><![CDATA[Papiss Cisse headed Newcastle into the quarter-finals of the Europa League with a stoppage-time winner against 10-man Anzhi Makhachkala.]]></description><link>http://www.skysports.com/football/match_report/0,19764,11065_3602530,00.html</link><guid isPermaLink="false">11959_8566188</guid><pubDate>Thu, 14 Mar 2013 22:02:58 GMT</pubDate><category>Report</category><enclosure type="image/jpg" url="http://img.skysports.com/13/03/128x67/Newcastle-v-Anzhi-Makhachkala-Papiss-Cisse-St_2915107.jpg" length="123456" /></item>
</channel>
</rss>
有人可以帮帮我吗?
谢谢
答案 0 :(得分:2)
echo "<img src=\"" . (string)$item->enclosure['url'][0] . "\">";