帝国CMS7.5正文图片自动加alt/title为标题教程,支持新增和修改。

1、将以下文本里提供的字段处理函数放入 e/class/userfun.php 文件中

function user_AddImgAlt($mid,$f,$isadd,$isq,$value,$cs){
$title=$_POST['title'];
$htmls=$value;
$pattern = "/<img[^>]+>/"; 
preg_match_all($pattern, $htmls, $matches); 
for ($i=0; $i<=count($matches[0]); $i++) {
preg_match_all("/alt=\".+?\"/",$matches[0][$i],$altimg); 
preg_match_all("/title=\".+?\"/",$matches[0][$i],$titleimg); 
$t_alt=count($altimg[0]);
if($t_alt==0){
$htmls=str_replace("<img","<img alt=\"{$title}\"",$htmls);
$htmls=str_replace("<img","<img title=\"{$title}\"",$htmls);
}
} 
return $htmls;
}

2、修改数据表中的正文字段

需要使用此功能的数据表都需要修改。正文字段一般是newstext(也可以是其它字段),在字段处理函数文本框填上user_AddImgAlt

3、其它说明

这个函数增加alt内容是强制性的,如果手动添加了alt也会被替换掉,使用时请注意。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注