进入文件/e/class/userfun.php,将如下函数加入其中
function getnewsimg($rid,$n){
global $empire,$dbtbpre,$class_r;
$fr=$empire->fetch1("select newstext from {$dbtbpre}ecms_news_data_1 where id='$rid'");
$newstext=stripslashes($fr['newstext']);
$pattern = '/<img.*?src.*?="(.*?)".*?>/i';
preg_match_all($pattern, $newstext, $match);
if(count($match[1])>=$n){
$diypic=$match[1][$n-1];
}else{
$diypic='/e/data/images/notimg.gif';
}
return $diypic;
}
模板中调用正文里的图片
<!--以下代码位于循环之中-->
<img src="<?=getnewsimg($bqr[id],1)?>">