操作方法如下:
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属性为信息标题了!
正在阅读:
帝国cms编辑文章上传图片将alt自动替换成文章标题title方法06-10
教师节活动策划书五篇08-23
2017年实习生预备党员思想汇报12-05
2022年重庆沙坪坝中考生物试题及答案(Word版)06-15
同学印象作文800字05-12
秋游作文300字(精选10篇)05-09
三年级周记大全300字:假如我是班主任11-22
春天作文600字08-17
关于电的作文400字08-03
难忘的“中考”作文450字10-17
2017党员四风自我剖析问题材料08-06