I am reading and store rss xml feed data in my database with images url and images and showing in my site url .for this I creat a function and its working well. but In a rss data I found a same image in different name and different size. like
<item>
<media:thumbnail url="http://a.abcnews.com/images/Entertainment/ap_tiger_woods_jp_111205_mn.jpg" width="320" height="240" credit="Danny Moloshok/AP Photo"/>
<media:thumbnail url="http://a.abcnews.com/images/Entertainment/ap_tiger_woods_jp_111205_mc.jpg" width="100" height="75" credit="Danny Moloshok/AP Photo"/>
<media:thumbnail url="http://a.abcnews.com/images/Entertainment/ap_tiger_woods_jp_111205_mv.jpg" width="264" height="198" credit="Danny Moloshok/AP Photo"/>
<media:thumbnail url="http://a.abcnews.com/images/Entertainment/ap_tiger_woods_jp_111205_wl.jpg" width="200" height="112" credit="Danny Moloshok/AP Photo"/>
<media:thumbnail url="http://a.abcnews.com/images/Entertainment/ap_tiger_woods_jp_111205_main.jpg" width="413" height="310" credit="Danny Moloshok/AP Photo"/>
<media:thumbnail url="http://a.abcnews.com/images/Entertainment/ap_tiger_woods_jp_111205_wmain.jpg" width="640" height="360" credit="Danny Moloshok/AP Photo"/>
<media:keywords>1</media:keywords>
<title><![CDATA[Change of Plans: Romney Revamps as Gingrich Closes]]></title>
<link><![CDATA[http://feeds.abcnews.com/click.phdo?i=b21d3190f683c1e9dd83653255d5e446]]></link>
</item>
<item>
<media:thumbnail url="http://a.abcnews.com/images/International/abc_rq170_unmanned_drone_ll_111205_mn.jpg" width="320" height="240" credit="ABC News"/>
<media:thumbnail url="http://a.abcnews.com/images/International/abc_rq170_unmanned_drone_ll_111205_mc.jpg" width="100" height="75" credit="ABC News"/>
<media:thumbnail url="http://a.abcnews.com/images/International/abc_rq170_unmanned_drone_ll_111205_mv.jpg" width="264" height="198" credit="ABC News"/>
<media:thumbnail url="http://a.abcnews.com/images/International/abc_rq170_unmanned_drone_ll_111205_wl.jpg" width="200" height="112" credit="ABC News"/>
<media:thumbnail url="http://a.abcnews.com/images/International/abc_rq170_unmanned_drone_ll_111205_main.jpg" width="413" height="310" credit="ABC News"/>
<media:thumbnail url="http://a.abcnews.com/images/International/abc_rq170_unmanned_drone_ll_111205_wmain.jpg" width="640" height="360" credit="ABC News"/>
<media:keywords>5</media:keywords>
<title><![CDATA[Iran Missing Drone Was on CIA Mission]]></title>
<link><![CDATA[http://feeds.abcnews.com/click.phdo?i=42a589abb9eb7a87c2dcaeaaeeb2e383]]></link>
and more...........
these all are same images in one item block with differ size.
and my function was for take image :
public function getNytimes($site_config = array()){
$xmlContent = self::checkXmlValidator($site_config['rss_link']);
if($xmlContent === false){
/*update url if getting any error*/
mysql_query("UPDATE feed_settings SET feed_settings.status = '0', feed_settings.error_log='Time:".date('Y-m-d H:i:s')." Invalid url or resopnse time too more' WHERE feed_settings.rss_link='".$site_config['id']."'");
return false;
}
$xml1 = new SimpleXMLElement($xmlContent);
$child = $xml1->getDocNamespaces();
$xml1->registerXPathNamespace('media', $child['media']);
$image_arr = $xml1->xpath('//media:content');
$xml = @simplexml_load_string($xmlContent,'SimpleXMLElement', LIBXML_NOCDATA);
for($counter = 0; $counter < sizeof($image_arr); $counter++){
$image = null;
$image = @$image_arr[$counter]->attributes()->url;
$sql_query = "INSERT INTO news_feeds SET `image_url` = '".$image."',
but this time its save 6 same image in database. so what can I do get the single image from one block?
如果图像几何是固定的,则只需使用指定的width和height属性保存图像。
Depends on what picture you'd like to save.
$image = @$image_arr[0]->attributes()->url;
This will save the pictures with the _mn
endfix. You remove the for-loop near the end of your script.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.