PHP提取字符串中的图片地址[正则表达式]
程序员文章站
2023-11-03 19:55:04
复制代码 代码如下:
<?php
$str='<p><img border="0" src="upfiles/2009/07/1246430143_1.jpg" alt=""/></p>';
$pattern="/<[img|img].*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/";
preg_match_all($pattern,$str,$match);
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
)
)
复制代码 代码如下:
<?php
$str='<p><img border="0" src="upfiles/2009/07/1246430143_1.jpg" alt=""/></p>';
$pattern="/<[img|img].*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/";
preg_match_all($pattern,$str,$match);
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
)
)
上一篇: vue addRoutes实现动态权限路由菜单的示例
下一篇: 汽车不好偷