图片批量替换url地址

function get_img_load_url($content="",$suffix="/images/load.gif")
{
    $pregRule = "/<[img|IMG].*?src=[\'|\"](.*?(?:[\.jpg|\.jpeg|\.png|\.gif|\.bmp]))[\'|\"].*?[\/]?>/";
    $content = preg_replace($pregRule, '<img src="'.$suffix.'" data-src="${1}">', $content);
    return $content;
}

$array = [
 	0 => '<p><img src="1.jpg" /></p>',
 	1 => '<p><img src="2.jpg" /></p>',
 	2 => '<p><img src="3.jpg" /></p>',
];

foreach ($array as $k => $v) {
 	$newImg = get_img_load_url($v);
 	print_r($newImg);
}

会飞的鱼博客
请先登录后发表评论
  • latest comments
  • 总共0条评论