随机获得文章中的四张图片中的一张
适用于多图站点,在模板文件中使用:
{php} $temp=mt_rand(1,4); $pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/"; $content = $article->Content;preg_match_all($pattern,$content,$matchContent); if(isset($matchContent[1][0])) $temp=$matchContent[1][0]; else $temp=$zbp->host."zb_users/theme/$theme/style/images/random/$temp.jpg"; //需要在相应位置放置4张jpg的文件,名称为1,2,3,4 {/php} <img src="{$temp}" />