織夢手機站去除文章內容中圖片的寬高達到自適應+絕對路徑圖片
阿新 • • 發佈:2020-08-13
大部分手機站都是自適應的,這樣圖片就不能有寬高限制,我們新增文章圖片時很多時候都會有width height style這些屬性在裡面,在手機站上要把它們清除並且讓圖片和附件都使用上絕對路徑,又不能影響電腦站的,不修改程式核心檔案,我們可以在手機版內容頁模板裡,
把手機站內容頁模板把呼叫文章內容的標籤,找到
{dede:field.body/}
改成
{dede:field.body runphp=yes} global $cfg_basehost; $str = @me; $search = '/(<img.*?)width=(["\'])?.*?(?(2)\2|\s)([^>]+>)/is'; $search1 = '/(<img.*?)height=(["\'])?.*?(?(2)\2|\s)([^>]+>)/is'; $search2 = '#(<img.*?style=".*?)width:\s{0,}\d+px;([^"]*?.*?>)#i'; $search3 = '#(<img.*?style=".*?)height:\s{0,}\d+px;([^"]*?.*?>)#i'; $content = preg_replace($search,'$1$3',$str); $content = preg_replace($search1,'$1$3',$content); $content = preg_replace($search2,'$1$2',$content); $content = preg_replace($search3,'$1$2',$content); @me = str_replace('/uploads/', $cfg_basehost.'/uploads/', $content); {/dede:field.body}
如果是欄目內容的圖片要自適應的話那標籤
{dede:field.content/}
改成
{dede:field.content runphp=yes} global $cfg_basehost; $str = @me; $search = '/(<img.*?)width=(["\'])?.*?(?(2)\2|\s)([^>]+>)/is'; $search1 = '/(<img.*?)height=(["\'])?.*?(?(2)\2|\s)([^>]+>)/is'; $search2 = '#(<img.*?style=".*?)width:\s{0,}\d+px;([^"]*?.*?>)#i'; $search3 = '#(<img.*?style=".*?)height:\s{0,}\d+px;([^"]*?.*?>)#i'; $content = preg_replace($search,'$1$3',$str); $content = preg_replace($search1,'$1$3',$content); $content = preg_replace($search2,'$1$2',$content); $content = preg_replace($search3,'$1$2',$content); @me = str_replace('/uploads/', $cfg_basehost.'/uploads/', $content); {/dede:field.content}