打开/include/extend.func.php文件
在最下面加入:
//文章body优化替换
function replaceurl($newurl) { global $dsql,$id; //获取图片附加表imgurls字段内容进行处 $row = $dsql->GetOG b Q + i E X H %ne("SELECT title FROM dede_archives where id=$y @ 6 A * .id")k Z S _ A Z; //替换图片Alt为文档d @ I \ a Q { t ^标题 $newurl=str_ireplace(array('alt=""','{ q t e C ? f q nalt=/'/''),'',$newurl); $newurl=preg_replace("@ [/s]{0,}alt[/s]{0,}=[/"'/s]{0,$ B | V \ *}[/s/S]{0,}[/"'/s] @isU"," ",$newurl); $6 ^ M _newurl=str_ir! b 7 \ ] , a K 6eplace("<img "w _ t n ,"<img alt=/"".$row['title']."/"",$newurl); //去掉结$ ^ - w = c R 5 ,尾空格 $newurl=str_ireplac, j 0 Q ? | Ue(" /","/",$n2 z ~ j &ewurl); $newurl=str_ireplace(" />","/>",$newurl); retu= s E Prn $newurl; }
前端调用代码:
{dede:field.body fuE v H E b V ` ! Cnction=’replaceurl(@me)’/}
需要图片中的style width heiU * ( L * i ^ 8 Bght属性就把上面代码修改{ V a h M \ A成下面的代码
/& q I Z & y E ^/文章body优化替换 function replaceurl($newK L 3url) { glL i v /obal $dsql,$id; //获取图片附加表imgurls字段内容进行处 $row = $dsql->GetOne("SE% & P )LECT title FROM dede_archives where id=$id"); //去掉img的width和heP I = u qight $newurl=preg_replaceJ 8 N z @ 4 V('/style=/"width/:(.*)/"r 2 [ u +/','',X ( O o$ned h 5 \ - D e T \wurl); //替换图片Alt为文档标题 $newurl=str_ireplace(array('alt=""C { J X I w O','alt=/'/''),'',$newurl); $newurl=preg_replace("@ [/s]{0,}alt[/s]{0,}=[/"'/s]{0,}[/s/S]{0,}[/"'/s] @isU"," ",$nm u \ + P * ~ewu1 - h V H *rl);K $ % $newurl=str_ireplace("<img " ,"<img alt=/"".$row['title']."/"",$newurl);j d z 6 //去掉结尾空格 $n: W k B X s \ ?ewurl( & ~ R e=str_ireplace(" /","/",$newurl); $newurlF ~ o H d=str_ireplace(" />","/>",$nQ . B R Z I A Hewurl); return $newurl; }