php获取文章中图片img标签方法
作者:Alpha时间:2017-09-14 阅读数:6500 +人阅读
php获取文章中图片img标签方法,适用于抓取图片,这里提供一个基本的方法,具体可以根据自己应用的需要进行拓展。
// 获取文章中图片img标签
function preg_image_html($content, $length = 9, $w = 100, $h = 100) {
preg_match_all ( '#<img.*?src="([^"]*)"[^>]*>#i', $content, $match );
$count_img = 0;
foreach ( $match [1] as $ik => $imgurl ) {
if ($count_img >= $length)
break;
if (! empty ( $imgurl )) {
// 过滤系统自带编辑器表情图片
if (preg_match ( '#^http://img.baidu.com/hi/#', $imgurl )) {
unset ( $match [1] [$ik] );
continue;
}
if (preg_match ( '#Uploads/Smiley/#', $imgurl )) {
unset ( $match [1] [$ik] );
continue;
}
$return [] = array (
0 => $imgurl,
1 => mk_rule_image ( $imgurl, $w, $h )
);
$count_img ++;
}
}
return $return;
}
本站所有文章、数据、图片均来自互联网,一切版权均归源网站或源作者所有。
如果侵犯了你的权益请来信告知我们删除。邮箱:595397166@qq.com