喜鹊没有得到 media:thumbnail 元素
Magpie not getting media:thumbnail element
我正在创建一个使用大量 rss 源的 php 脚本。它将 rss 提要放入数据库中。
有多种方法可以将 thumbnail/image 放入 xml 文件中。我对一种特定方式有疑问。
当 xml 文件包含如下内容时:Source
...
<media:content type="image/jpeg" url="http://static3.hln.be/static/photo/2015/1/8/6/20150405151722/crop_7613016.jpg">
<media:thumbnail url="http://static3.hln.be/static/photo/2015/1/8/6/20150405151722/crop_7613016.jpg"/>
</media:content>
...
出于某种原因,MagPie 似乎没有获取该元素。如果我 var_dump 该项目看起来像这样:
...
["media"]=> array(1) { ["content"]=> string(1) " " } ["content"]=> string(1) " "
...
有人知道我如何提取缩略图元素吗?
提前致谢。
更新-(一些示例代码):
$rss = fetch_rss('http://www.hln.be/rss.xml');
foreach ($rss->items as $item )
{ //loop through rss feed
var_dump($item); //the var_dump without media elements
return $array = $arrayName = array(
'title' => $item['title'],
'url' => $item['link'],
...);
putDataInDatabase(); //put everything in the database
}
更全面地了解 var_dump
array(10) { ["title"]=> string(62) "Isinbayeva ..."" ["link"]=> string(23) "http://s.hln.be/2276986" ["description"]=> string(141) "Yelena Isinbayeva ..." ["pubdate"]=> string(29) "Sun, 05 Apr 2015 13:06:00 GMT" ["author"]=> string(8) "redactie" ["guid"]=> string(23) "http://s.hln.be/2276986" ["media"]=> array(1) { ["content"]=> string(1) " " } ["content"]=> string(1) " " ["summary"]=> string(141) "Yelena Isinbayeva wil... " ["date_timestamp"]=> int(1428239160) }
元素在该数组中,例如您可以像这样访问内容缩略图的 URL:
$item['media']['content_thumbnail@url']
从您的示例的角度来看:
$rss = fetch_rss('http://www.hln.be/rss.xml');
foreach ($rss->items as $item) { //loop through rss feed
var_dump($item['media']['content_thumbnail@url']);
}
给出以下输出:
string(79) "http://static3.hln.be/static/photo/2015/2/10/14/20150405204108/crop_7613834.jpg"
string(78) "http://static0.hln.be/static/photo/2015/1/9/13/20150405201321/crop_7613833.jpg"
string(77) "http://static2.hln.be/static/photo/2015/7/0/8/20150405203748/crop_7613858.jpg"
string(77) "http://static2.hln.be/static/photo/2015/0/6/8/20150405200321/crop_7613813.jpg"
string(79) "http://static2.hln.be/static/photo/2015/17/6/10/20150405200509/crop_7613830.jpg"
string(77) "http://static1.hln.be/static/photo/2015/7/9/7/20150405195208/crop_7613782.jpg"
string(78) "http://static2.hln.be/static/photo/2015/0/15/7/20150405193052/crop_7613737.jpg"
...
这是媒体元素的整体结构:
Array
(
[content#] => 1
[content@] => type,url
[content@type] => image/jpeg
[content@url] => http://static3.hln.be/static/photo/2015/2/10/14/20150405204108/crop_7613834.jpg
[content] =>
[content_thumbnail#] => 1
[content_thumbnail@] => url
[content_thumbnail@url] => http://static3.hln.be/static/photo/2015/2/10/14/20150405204108/crop_7613834.jpg
)
我正在创建一个使用大量 rss 源的 php 脚本。它将 rss 提要放入数据库中。 有多种方法可以将 thumbnail/image 放入 xml 文件中。我对一种特定方式有疑问。
当 xml 文件包含如下内容时:Source
...
<media:content type="image/jpeg" url="http://static3.hln.be/static/photo/2015/1/8/6/20150405151722/crop_7613016.jpg">
<media:thumbnail url="http://static3.hln.be/static/photo/2015/1/8/6/20150405151722/crop_7613016.jpg"/>
</media:content>
...
出于某种原因,MagPie 似乎没有获取该元素。如果我 var_dump 该项目看起来像这样:
...
["media"]=> array(1) { ["content"]=> string(1) " " } ["content"]=> string(1) " "
...
有人知道我如何提取缩略图元素吗? 提前致谢。
更新-(一些示例代码):
$rss = fetch_rss('http://www.hln.be/rss.xml');
foreach ($rss->items as $item )
{ //loop through rss feed
var_dump($item); //the var_dump without media elements
return $array = $arrayName = array(
'title' => $item['title'],
'url' => $item['link'],
...);
putDataInDatabase(); //put everything in the database
}
更全面地了解 var_dump
array(10) { ["title"]=> string(62) "Isinbayeva ..."" ["link"]=> string(23) "http://s.hln.be/2276986" ["description"]=> string(141) "Yelena Isinbayeva ..." ["pubdate"]=> string(29) "Sun, 05 Apr 2015 13:06:00 GMT" ["author"]=> string(8) "redactie" ["guid"]=> string(23) "http://s.hln.be/2276986" ["media"]=> array(1) { ["content"]=> string(1) " " } ["content"]=> string(1) " " ["summary"]=> string(141) "Yelena Isinbayeva wil... " ["date_timestamp"]=> int(1428239160) }
元素在该数组中,例如您可以像这样访问内容缩略图的 URL:
$item['media']['content_thumbnail@url']
从您的示例的角度来看:
$rss = fetch_rss('http://www.hln.be/rss.xml');
foreach ($rss->items as $item) { //loop through rss feed
var_dump($item['media']['content_thumbnail@url']);
}
给出以下输出:
string(79) "http://static3.hln.be/static/photo/2015/2/10/14/20150405204108/crop_7613834.jpg"
string(78) "http://static0.hln.be/static/photo/2015/1/9/13/20150405201321/crop_7613833.jpg"
string(77) "http://static2.hln.be/static/photo/2015/7/0/8/20150405203748/crop_7613858.jpg"
string(77) "http://static2.hln.be/static/photo/2015/0/6/8/20150405200321/crop_7613813.jpg"
string(79) "http://static2.hln.be/static/photo/2015/17/6/10/20150405200509/crop_7613830.jpg"
string(77) "http://static1.hln.be/static/photo/2015/7/9/7/20150405195208/crop_7613782.jpg"
string(78) "http://static2.hln.be/static/photo/2015/0/15/7/20150405193052/crop_7613737.jpg"
...
这是媒体元素的整体结构:
Array
(
[content#] => 1
[content@] => type,url
[content@type] => image/jpeg
[content@url] => http://static3.hln.be/static/photo/2015/2/10/14/20150405204108/crop_7613834.jpg
[content] =>
[content_thumbnail#] => 1
[content_thumbnail@] => url
[content_thumbnail@url] => http://static3.hln.be/static/photo/2015/2/10/14/20150405204108/crop_7613834.jpg
)