每篇内容根据段落判断插入图片代码附上:
$chatd="<table>";if(stripos($content,$chatd)==0){//随机输出三张图功能if($moduleid!=37 &&$thumb==''){//判断是否存在图$id=rand(1,999999);$mid=rand(1,9999999);$getimg="http://www.nongpin88.com/randimage/".$moduleid."/".$itemid.".png";$getimgs="http://www.nongpin88.com/randimage/".$moduleid."/".$id.".png";$getimgss="http://www.nongpin88.com/randimage/".$moduleid."/".$mid.".png";$count = substr_count($content,'</p>');//获取p标签的数量$j = 0;//</p>重新定位用的//判断多少个pif($count<9){$num = 0;//这里是在1/3的位置插入,可以修改为rand(1,$count);这样就是随机位置插入了if($count<6){$numone=null;$numtwo=null; }else{$numone=($count-1);$numtwo=null;}}elseif($count>8 && $count<12){$num = 1;$numone=6;$numtwo=9;}else{$num = 1;$numone=floor($count/2);$numtwo=($count-1);}for($i = 0; $i < $count; $i++){$j = strpos($content, '</p>', $j);if($i == $num){$content = substr($content, 0, $j) . ('<p><img src="' .$getimg .'" /></p>') . substr($content, $j); }elseif($i==$numone){$content = substr($content, 0, $j) . ('<p><img src="' .$getimgs .'" /></p>') . substr($content, $j);}elseif($i==$numtwo){$content = substr($content, 0, $j) . ('<p><img src="' .$getimgss .'" /></p>') . substr($content, $j); }$j = ($j+1);}}}
这样就ok了,根据段落自动插入图片
演示地址:校园欺凌的观后感_醉学网