duangong937906 2014-07-24 14:42
浏览 23
已采纳

如何从HTML代码中提取图像

I’m using Magepierss to extract feeds news from some urls i get the title, the date, etc.. But not the image, it’s exist in this fields [description] within a html code

[description] => <div style="margin: 5px 5% 10px 5%;"><img src="http://www.supermotoaustralia.com/wp-content/uploads/2014/07/showroom.jpg" width="90%" /></div><div>Australians purchased 53,396 new motorcycles, all-terrain vehicles (ATVs) and scooters in the first half of 2014, with road motorcycle purchases making up 40.6 per cent of these sales. While sales in the road motorcycle segment were up 2.2 per cent, total motorcycle, ATV and scooter sales were down 0.5 per cent compared to the same [&#8230;]</div>

and i want to do a function in php to exctrat just the image frome this html code any ideas ?

  • 写回答

4条回答 默认 最新

  • doujishao8793 2014-07-24 14:54
    关注

    You need to use regex.Try this :

    $str = '<div style="margin: 5px 5% 10px 5%;"><img src="http://www.supermotoaustralia.com/wp-content/uploads/2014/07/showroom.jpg" width="90%" /></div><div>Australians purchased 53,396 new motorcycles, all-terrain vehicles (ATVs) and scooters in the first half of 2014, with road motorcycle purchases making up 40.6 per cent of these sales. While sales in the road motorcycle segment were up 2.2 per cent, total motorcycle, ATV and scooter sales were down 0.5 per cent compared to the same [&#8230;]</div>';
    
    
    $rx_main = '(<img src="(.+)")Ui';
    preg_match($rx_main,$str,$result); 
    
    print_r($result[1]);// will produce http://www.supermotoaustralia.com/wp-content/uploads/2014/07/showroom.jpg
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应