帝国cms内容页图片alt标签自动设置为title教程

2019-12-27 10:29:12 80 0 编辑:亿网科技有限公司 来源:本站原创
操作方法如下:

1.把下面的代码放到/e/class/userfun.php   (放到最后?>的前面)
 
function user_imgalt($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_imgalt 如下图:
帝国cms内容页图片alt标签自动设置为title教程
3.发布信息的时候就可以自动替换图片alt和title属性为信息标题了!大家可以试试看。
本站文章均为<亿网科技有限公司>网站建设摘自权威资料,书籍,或网络原创文章,如有版权纠纷或者违规问题,请即刻联系我们删除,我们欢迎您分享,引用和转载,我们谢绝直接复制和抄袭!
我们猜你喜欢