PHP提取字符串中的图片地址[正则表达式]
(编辑:jimmy 日期: 2024/11/18 浏览:3 次 )
复制代码 代码如下:
<?php
$str='<p><img border="0" src="/UploadFiles/2021-04-02/1246430143_1.jpg">$pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/";
preg_match_all($pattern,$str,$match);
print_r($match);
?>
结果显示:
Array
(
[0] => Array
(
[0] => <img border="0" src="/UploadFiles/2021-04-02/1246430143_1.jpg">)
[1] => Array
(
[0] => upfiles/2009/07/1246430143_1.jpg
)
)
<?php
$str='<p><img border="0" src="/UploadFiles/2021-04-02/1246430143_1.jpg">$pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/";
preg_match_all($pattern,$str,$match);
print_r($match);
?>
结果显示:
Array
(
[0] => Array
(
[0] => <img border="0" src="/UploadFiles/2021-04-02/1246430143_1.jpg">)
[1] => Array
(
[0] => upfiles/2009/07/1246430143_1.jpg
)
)
下一篇:PHP学习散记_编码(json_encode 中文不显示)