我这是笨办法,没有楼上的高明(高明的不分享啊【高明=高冷】)
$classid=$r[classid]; //获取栏目id $tbname=$class_r[$classid][tbname];//获取数据表 $fr=$empire->fetch1("select newstext from {$dbtbpre}ecms_".$tbname."_data_{$r[stb]} where id='$r[id]'"); $str=stripcslashes($fr['newstext']); preg_match_all('/<img.*?src="(.*?)".*?>/is',$str,$imgArr); $imgArr = array_unique($imgArr[1]);
$pattern = '/<img(?=\\s).*?(?<=\\s)src="(.+?)"/i'; $pics=preg_match_all($pattern, $str, $matches); //$pics为内容文中图片数量
if($pics==0){$tu1 = '';} if($pics<=2 and $pics>0){$tu1 = '第1张:<img src="'.$imgArr[0].'" width="20" height="20" />';} if($pics>=3){$tu1 = '第1张:<img src="'.$imgArr[0].'" width="20" height="20" />'; $tu2 = '第2张:<img src="'.$imgArr[1].'" width="20" height="20" />'; $tu3 = '第3张:<img src="'.$imgArr[2].'" width="20" height="20" />';}
$listtemp='<li> <span class="datetime">[!--newstime--]</span> <a href="[!--titleurl--]" title="[!--oldtitle--]">[!--title--]</a> (共'.count($imgArr).'张) '.$tu1.''.$tu2.''.$tu3.'</li>';
样式自己调吧
|