请教如何用php提取图片url地址

2025-04-29 06:37:36
推荐回答(1个)
回答1:

1楼的不太符合实际情况,
$str='

';
$pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/";
preg_match_all($pattern,$str,$match);
print_r($match);

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

直接获取图片 echo current($match[1]);