Dedecms去掉文章内容中的图片宽度和高度限制的办法

COS、CDN
  1. 在内容页修改 {dede:field.body}

    {dede:field.body runphp=yes} global $cfg_basehost; $str = @me; $search = '/(]+>)/is'; $search1 = '/(]+>)/is'; $search2 = '#()#i'; $search3 = '#()#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 = $content; //@me = str_replace('/uploads/allimg/', $cfg_basehost . '/uploads/allimg/', $content); // 手机版图片使用绝对路径 {/dede:field.body}
  2. 在保存时进行处理

    • 修改 /dede/article_add.php 和 /dede/article_edit.php 文件:
      $body = AnalyseHtmlBody($body, $description, $litpic, $keywords, 'htmltext'); // 去除img中的style属性 $body = preg_replace("/style=\.[^'\"<>]*['\"]/i", "", $body); // 去除img中的width,height属性 $exp = array("/height=.{0,5}\s/i", "/width=.{0,5}\s/i"); $exp_o = array("", ""); $body = preg_replace($exp, $exp_o, $body);

       

COS、CDN
热门