thinkphp 从文章截取前三张图片的路径
function getImgUrl($content){
$soContent=$content;
$soImages = "/<img.*>/isU";
preg_match_all($soImages, $content, $thePics);
$pic_count = count($thePics[0]);
$rtn="[";
for($i=0;$i<$pic_count&&$i<3;$i++){//这里仅截取前三个,如果需要更多,请调整这里。
preg_match("|src="(.*)"|isU",$thePics[0][$i],$match);
$rtn.="{"url":"".$match[1].""},";
}
if($this->endWith($rtn,",")){
$rtn=substr($rtn, 0,strlen($rtn)-1);
}
$rtn.="]";
$rtn=str_replace("\", "/", $rtn);
return $rtn;
}返回结果格式为json,如果需要标准json格式,需要在$rtn外边再加一对中括号即可。声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: 面试题:最常见最有可能考到的C语言面试题汇总
- 下一篇: 关于如何php如何提取发布文章中第一张图片
