网站模板仿制之提取页面图片的正则表达式
2024-12-29 21:54:06网站扒皮
摘要:获取html页面所有的图片URL的函数
// 匹配所有以.jpg, .jpeg, .gif, .png, .bmp, .svg, .webp, .avif结尾的src属性值
$pattern = '/]+src="(?[^"]+\.(jpg|jpeg|gif|png|bmp|svg|webp|avif))"[^>]*>/i';
preg_match_all($pattern, $content, $matches);
$arr_images=array();//原始图片集合
if(isset($matches['url'])){
foreach ($matches['url'] as $key => $value) {
if(!in_array($value, $arr_images))
$arr_images[]=$value;
}
}
$pattern = '/]+src="(?
preg_match_all($pattern, $content, $matches);
$arr_images=array();//原始图片集合
if(isset($matches['url'])){
foreach ($matches['url'] as $key => $value) {
if(!in_array($value, $arr_images))
$arr_images[]=$value;
}
}