实现功能:正文里的图片自动加上alt值,alt值为信息标题。分两步实现:
1、将以下字段处理函数放入 e/class/userfun.php 文件中
function user_AddImgAlt($mid,$f,$isadd,$isq,$value,$cs){
$title=str_replace('"','',$_POST['title']);
$htmls=$value;
$pattern = "/]+>/";
preg_match_all($pattern,$htmls,$matches);
$m=count($matches[0]);
for($i=0;$i<=$m;$i++){
preg_match_all("/alt=".+?"/",$matches[0][$i],$altimg);
$t_alt=count($altimg[0]);
if($t_alt==0){
$htmls=str_replace("<img",")/i',$value,$altimg);
foreach($altimg[0] as $altstr){
$value=str_replace($altstr,"[----dp1037----]",$value);
}
$title=str_replace(array('"','>','/'),'',$_POST['title']);
$newalt=' alt="'.$title.'" ';
$value=str_replace("[----dp1037----]",$newalt,$value);
return $value;
}
此文由 at-lib网站目录 编辑,未经允许不得转载!: