织梦怎么让文章中图片自动添加ALT属性

打开/include/extend.func.php文件

在最下面加入:

1//文章body优化替换
04//获取图片附加表imgurls字段内容进行处
01function replaceurl($newurl)
02{
03global $dsql,$id;
 
05$row = $dsql->GetOne("SELECT title FROM dede_archives where id=$id");
06//替换图片Alt为文档标题
07$newurl=str_ireplace(array('alt=""','alt=/'/''),'',$newurl);
08$newurl=preg_replace("@ [/s]{0,}alt[/s]{0,}=[/"'/s]{0,}[/s/S]{0,}[/"'/s] @isU"," ",$newurl);
09$newurl=str_ireplace("<img " ,"<img  alt=/"".$row['title']."/"",$newurl);
10//去掉结尾空格
11$newurl=str_ireplace(" /","/",$newurl);
12$newurl=str_ireplace(" />","/>",$newurl);
13return $newurl;
14}

前端调用代码:

{dede:field.body function=’replaceurl(@me)’/}

需要图片中的style width height属性就把上面代码修改成下面的代码

01//文章body优化替换
02function replaceurl($newurl)
03 {
04global $dsql,$id;
05//获取图片附加表imgurls字段内容进行处
06$row = $dsql->GetOne("SELECT title FROM dede_archives where id=$id");
07//去掉img的width和height
08$newurl=preg_replace('/style=/"width/:(.*)/"/','',$newurl);
09//替换图片Alt为文档标题
10$newurl=str_ireplace(array('alt=""','alt=/'/''),'',$newurl);
11$newurl=preg_replace("@ [/s]{0,}alt[/s]{0,}=[/"'/s]{0,}[/s/S]{0,}[/"'/s] @isU"," ",$newurl);
12$newurl=str_ireplace("<img " ,"<img  alt=/"".$row['title']."/"",$newurl);
13//去掉结尾空格
14$newurl=str_ireplace(" /","/",$newurl);
15$newurl=str_ireplace(" />","/>",$newurl);
16return $newurl;
17 }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值