欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

dedecms

當前位置:主頁 > CMS教程 > dedecms >

織夢在PHP7.0環(huán)境中為文章圖片自動添加ALT屬性為標題方法

來源:本站原創(chuàng)|時間:2021-08-05|欄目:dedecms|點擊: 次

織夢在PHP7.0環(huán)境中為文章圖片自動添加ALT屬性為標題方法,首先修改/include/extend.func.php,里面的把這段代碼加進去:

//文章body優(yōu)化替換
        function replaceurl($newurl)
        {
        global $dsql,$id;
        //獲取圖片附加表imgurls字段內(nèi)容進行處
        $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);
        //去掉結(jié)尾空格
        $newurl=str_ireplace(" /","/",$newurl);
        $newurl=str_ireplace(" />","/>",$newurl);
        return $newurl;
        }

然后在我們需要調(diào)用織夢文章內(nèi)容的地方加上調(diào)用代碼:
 
{dede:field.body function='replaceurl(@me)'/}
 
由于之前在《織夢如何去除img圖片中的style width height屬性》一文中,實現(xiàn)去高寬屬性,既然我們今天用自定義函數(shù)實現(xiàn)了替換alt屬性,那么也可以把去高寬屬性的這個功能加進去,完整代碼如下:

//文章body優(yōu)化替換
    function replaceurl($newurl)
     {
    global $dsql,$id;
    //獲取圖片附加表imgurls字段內(nèi)容進行處
    $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);
    //去掉結(jié)尾空格
    $newurl=str_ireplace(" /","/",$newurl);
    $newurl=str_ireplace(" />","/>",$newurl);
    return $newurl;
     }

 

上一篇:織夢后臺提示:DedeCMS Error:Tag disabled:php!解決方法

欄    目:dedecms

下一篇:織夢Dedecms上下篇文章標題字數(shù)截取方法

本文標題:織夢在PHP7.0環(huán)境中為文章圖片自動添加ALT屬性為標題方法

本文地址:http://mengdiqiu.com.cn/a1/dedecms/14001.html

更多dedecms

您可能感興趣的文章

閱讀排行

本欄相關(guān)

隨機閱讀

網(wǎng)頁制作CMS教程網(wǎng)絡編程軟件編程腳本語言數(shù)據(jù)庫服務器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有