方法代码

function thumbcon($con) {


preg_match_all("/\<img.*?src\=(\'|\")(.*?)(\'|\")[^>]*>/i", $con, $matches);
$imgCount = count($matches[0]);
if($imgCount >= 1){
$img = $matches[2][1];
}
if(!$img){
$rand_num = 5; 
$img = Helper::options()->siteUrl."usr/themes/pure/randimg/".rand(1,$rand_num).".jpg?imageMogr2/format/webp";
}
return $img;



}

调用方法自己参考

style="background-image:url(<?php echo thumbcon($this->content); ?>)"

扫描二维码,在手机上阅读!