码迷,mamicode.com
首页 > 其他好文 > 详细

接口去除标签并且提取图片视频

时间:2018-12-06 14:35:15      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:text   ref   edit   使用   去除   iframe   取数据   http   com   

public function contents($content)
{
$content = preg_replace(‘/<img\s.*?src="(.*?)"\/>/‘,‘{[src="$1"{[‘,$content);//匹配图片
$content = preg_replace(‘/<iframe\s(.*?src=(.*?)\s.*?)<\/iframe>/‘,‘{[$1{[‘,$content);
$content = preg_replace(‘/<a\shref=("\/[a-z]{3,}\/[a-z]{3,}\/[0-9]{2,15}\.html"\s.*?>.*?)<\/a>/‘,‘{[$1{[‘,$content);//匹配a链接
$content = preg_replace(‘/<\/li>/‘,PHP_EOL,$content);
$content = preg_replace(‘/&nbsp;/‘,‘‘,$content);
$content = preg_replace(‘/<\/br>/‘,PHP_EOL,$content);
$content = preg_replace(‘/<\/p>/‘,PHP_EOL,$content);
$content = strip_tags($content);
if($content)
{
$content = explode(‘{[‘,$content);
if($content)
{
foreach($content as $k => $v)
{
if(trim($v,PHP_EOL))
{
$ter = preg_match(‘/"\/.*?\/[\w\-]{8,11}\/[A-Za-z0-9]{10,20}.[a-z]{3,4}"/‘,$v,$m);//匹配图片
$href = preg_match(‘/"\/[a-z]{3,}\/[a-z]{3,}\/([0-9]{2,15})\.html"/‘,$v,$h);//匹配链接
$movie = preg_match(‘/http:.*?[",\s]/‘,$v,$e);//匹配视频
$e[0]=trim($e[0]);//去两边字符
$e[0] = str_replace(‘"‘,‘‘,$e[0]);//把双引号去掉
if($ter)
{
$m = str_replace(‘"‘,‘‘,$m);
$size = getimagesize(‘../thinkphp‘.$m[0]);
//服务器上图片使用路径
$m = preg_replace(‘/\/ueditor/‘,‘http://www.acg170.com/ueditor‘,$m);
$m = preg_replace(‘/\/Public/‘,‘http://www.acg170.com/Public‘,$m);
$arr[$k][0] = ‘img‘;
$arr[$k][1] = [[$m[0],$size[0],$size[1]],‘‘];
}elseif($movie)
{
$arr[$k][0] = ‘movie‘;
$hei = preg_match(‘/height[=,:]([0-9]{3})/‘,$v,$height);
if ($hei) {
$arr[$k][1] = [$e[0],$height[1]];
}else{
$arr[$k][1] = [$e[0],‘‘];
}
}elseif($href){//a链接
$arr[$k][0] = ‘link‘;
preg_match(‘/[0-9]{2,}/‘,$v,$id);//获取数据id
preg_match(‘/">([\s\S]*)/‘,$v,$text);//获取文字内容
$arr[$k][1] = [$id[0],$text[1],‘0‘];
}else{
$arr[$k][0] = ‘text‘;

$arr[$k][1] = [$v];
}
}
}
}
}
return $arr;
}

接口去除标签并且提取图片视频

标签:text   ref   edit   使用   去除   iframe   取数据   http   com   

原文地址:https://www.cnblogs.com/yang1022/p/10076057.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!