PHP提取字符串中的图片地址

1 $str='<p><img border="0" src="upfiles/2009/07/1246430143_1.jpg" alt=""/></p>';
2 $pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/";
3 preg_match_all($pattern,$str,$match);
4 print_r($match);

结果显示:

Array
(
    [0] => Array
        (
            [0] => <img border="0" src="upfiles/2009/07/1246430143_1.jpg" alt=""/>
        )

    [1] => Array
        (
            [0] => upfiles/2009/07/1246430143_1.jpg
        )

)

转载于:https://www.cnblogs.com/in-loading/archive/2011/11/22/2258373.html

猜你喜欢

转载自blog.csdn.net/weixin_33797791/article/details/93700323