php 正则匹配img标签

 1 header("Content-type: text/html; charset=utf8");
 2 date_default_timezone_set("Asia/Shanghai");
 3 
 4 
 5 $str='551<img src="/upload/image/2016/07/29/14/20160729140622_51061.png" alt="" /><img src="/upload/image/2016/07/29/14/20160729140622_510331.png" alt="" /><img src="" alt="" />';
 6 $pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/";
 7 preg_match_all($pattern,$str,$match);
 8 //print_r($match[1]);
 9 //echo "<hr>";
10 $str2=html_entity_decode(stripslashes($str));
11 preg_match_all('/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/',$str2,$match2);
12 //print_r($match2[1]);
13 //echo "<hr>";
14 //echo strip_tags($str2,'img');
15 $content='潍坊新亚金属制品有限公司位于风景秀丽国际宝石之城---昌乐。我公司一直专注于锌合金、铝合金的研发、生产和销售。“节能环保、绿色工厂”是新亚人的办厂理念,贯穿公司科研、生产和产品供应的各个方面。   公司采用先进的清洁能源制造设备、高效熔炼炉生产锌合金,既可降低能耗,节约成本,又绿色环保,不污染成品。新亚牌压铸锌合金具有结晶细密、抗氧化性能好、强度高、性能稳定、复熔温度低、压>>>更多详情';
16 $str='<a href="{url:/goods/company_reviewEdit/id/$item[uid]}"><span style="color:#FF0000;">>>>更多详情</span></a>';
17 echo preg_replace('/\>\>\>更多详情/',$str,$content);

 

posted @ 2016-08-01 14:54  _DongGe  阅读(1974)  评论(0编辑  收藏  举报