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 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启