最新文章

点击排行

最新评论

当前位置:首页 > 网站制作 >
帝国cms文章图片自动添加alt为标题
发表日期:2014-05-27 13:18 来源: 浏览: 评论:

  默认情况下,图片上传d时候叫什么名字,alt里面就匙什么...
 
  为了SEO有时都要手动把里面改成想要d,比如标题
 
  现在使用字段处理函数来解决
 
  把一下代码放入e/userfun.php文件里面
//替换正文IMG里dALT内容  
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]);   oleou.com
        if($t_alt==0){  
            $htmls=str_replace("<img","<img alt="{$title}"",$htmls);  
        }else{  
            $htmls=str_replace($altimg[0][0],"alt="{$title}"",$htmls);  
        }  
    }     
        return $htmls;  
}

OLEOU 2018
返回顶部