易仿帝国yfdiguo.com

您当前的位置:首页 > 问题库

帝国CMS发布信息时替换正文IMG图片标签里ALT内容的方法

zcmcss发表于2017-12-11问题库

打开 e/class/userfun.php 文件,并增加
//替换正文IMG里的ALT内容
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);
        $t_alt=count($altimg[0]);
        if($t_alt==0){
            $htmls=str_replace("<img","<img alt=/"{$title}/"",$htmls);
        }
    }   
        return $htmls;
}

然后在后台系统设置-数据表模型-字段管理里面 编辑 newstext字段
增加如下
[CropImg][URL]a179553e756ad5aaecf7f46df3fe54a6.jpg
即可,图片上的alt就自动被替换成了文章标题 适合seo!

©2017 易仿帝国yfdiguo.com


友情链接: 阿里云优惠网| 阿里云推荐码| 阿里云教程| 莫愁博客|
♥ www.yfdiguo.com
联系作者QQ: