打开/include/extend.func.php文件
在最下面加入:

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

前端调用代码:
{dede:field.body function=’replaceurl(@me)’/}
需要图片中的style width height属性就把上面代码修改成下面的代码

//文章body优化替换
function replaceurl($newurl)
{
global $dsql,$id;
//获取图片附加表imgurls字段内容进行处
$row = $dsql->GetOne("SELECT title FROM dede_archives where id=$id");
//去掉img的width和height
$newurl=preg_replace('/style=/"width/:(.*)/"/','',$newurl);
//替换图片Alt为文档标题
$newurl=str_ireplace(array('alt=""','alt=/'/''),'',$newurl);
$newurl=preg_replace("@ [/s]{0,}alt[/s]{0,}=[/"'/s]{0,}[/s/S]{0,}[/"'/s] @isU"," ",$newurl);
$newurl=str_ireplace("<img " ,"<img  alt=/"".$row['title']."/"",$newurl);
//去掉结尾空格
$newurl=str_ireplace(" /","/",$newurl);
$newurl=str_ireplace(" />","/>",$newurl);
return $newurl;
}

免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。