// 匹配<img>标签的表达式
$preg = "/<img.*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/i";
示例:
$img='<div class="div"><img class="img" width="200" height="100" src="./../images/img.jpg" /></div>';
$preg = "/<img.*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/i";
preg_match_all($preg,$img,$arr);
print_r($arr);
运行结果:
Array
(
[0] => Array
(
[0] => <img class="img" width="200" height="100" src="./../images/img.jpg" />
)
[1] => Array
(
[0] => ./../images/img.jpg
)
)