纵有疾风起
人生不言弃

php 提取网页中所有图片

/* 提取所有图片 */

$content =file_get_content(“url”);

getImgs($content);

function getImgs($content, $order = ‘all’) {
$pattern = “/<img.*?src=[\’|\”](.*?(?:[\.gif|\.jpg|\.png]))[\’|\”].*?[\/]?>/”;
preg_match_all($pattern, $content, $match);
if (isset($match[1]) && !empty($match[1])) {
if ($order === ‘all’) {
return $match[1];
}
if (is_numeric($order) && isset($match[1][$order])) {
return $match[1][$order];
}
}
return ”;
}

未经允许不得转载:起风网 » php 提取网页中所有图片
分享到: 生成海报

评论 抢沙发

评论前必须登录!

立即登录