我有一个这种结构的RSS Feed:
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:media="http://search.yahoo.com/mrss/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
>
<channel>
<title>Title</title>
<atom:link href="url" rel="self" type="application/rss+xml" />
<link>url</link>
<description>desc</description>
<lastBuildDate>Tue, 21 Oct 2014 12:50:06 +0000</lastBuildDate>
<language>en-EN</language>
<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<generator>http://wordpress.org/?v=3.8.1</generator>
<item>
<title>Hello</title>
<link>helloUrl/</link>
<comments>comments</comments>
<pubDate>Tue, 21 Oct 2014 12:44:18 +0000</pubDate>
<dc:creator><![CDATA[admin]]></dc:creator>
<category><![CDATA[General]]></category>
<guid isPermaLink="false">permalink</guid>
<description><![CDATA[this is a description]]></description>
<media:content url="IMAGEurl" medium="image" />
<content:encoded><![CDATA[<a href="http://www.youtube.com/watch?v=">http://www.youtube.com/watch?v=</a><p><a href="imageURL" rel="lightbox[68]"><img class="wp-image-67 alignleft" alt="alt" src="imageURL" width="164" height="164" /></a>
<p> </p><object data="http://www.youtube.com/v/?version=3&rel=0&fs=1&showinfo=0" type="application/x-shockwave-flash" width="604" height="370">
<param name="movie" value="http://www.youtube.com/v/?version=3&rel=0&fs=1&showinfo=0"></param>
<param name="wmode" value="opaque"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowScriptAccess" value="always"></param>
</object>
<p><a href="http://www.youtube.com/watch?v="><img src="http://img.youtube.com/vi//default.jpg" width="130" height="97" border=0></a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=" id="wpa2a_2"><img src="/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
<wfw:commentRss>feedURL</wfw:commentRss>
<slash:comments>0</slash:comments>
</item>
.
.
为了获取所包含的信息,这是我的php:
<?php
$url ="myrss.rss";
$rss = simplexml_load_file($url);
if($rss)
{
echo '<h1>'.$rss->channel->title.'</h1>';
echo '<li>'.$rss->channel->pubDate.'</li>';
$items = $rss->channel->item;
foreach($items as $item)
{
$title = $item->title;
$link = $item->link;
$published_on = $item->pubDate;
$description = $item->description;
echo '<h3><a href="'.$link.'">'.$title.'</a></h3>';
echo '<span>('.$published_on.')</span>';
echo '<p>'.$description.'</p>';
$ns_media = $item->children('http://search.yahoo.com/mrss/');
echo $ns_media->content;
}
}
所有内容都正在打印,但是对于图片网址。我需要图片网址,以便我可以使用来自RSS Feed的图片和文字构建一个网页。
我做错了什么?
谢谢!
解决:
以防有人需要它:
不要使用simplexml_load_file
使用
$rss = file_get_contents('myrss.xml');
$rss = str_replace('<media:', '<', $rss);