本站资源均来自互联网,仅供学习与参考,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
Copyright @ 2015-2020 织梦园 版权所有
Power by DedeCms
鲁ICP备15039853号-1
鲁公网安备 37132302000249号
模板标签 TAG标签 网站地图 XML地图 今日更新 返回顶部
打开/include/extend.func.php文件
在***下面加入:
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; } |