Heim  >  Artikel  >  Backend-Entwicklung  >  phpcms 文章内容图片缩略步骤

phpcms 文章内容图片缩略步骤

WBOY
WBOYOriginal
2016-06-13 12:40:551141Durchsuche

phpcms 文章内容图片缩略方法

在/phpcms/modules/content/index.php中修改

方法就是匹配出img 图片地址,用thumb进行缩放替换在展现出来。

?

?

在show()方法中,修改$content

?

content = preg_replace('/<img [^ alt=" phpcms  文章内容图片缩略步骤 " >]*src=[\'"]?([^>\'"\s]*)[\'"]?[^>]*>/ie',"self::changeThumb('$0','$1')",$content);

??

匹配图片,交给本身类函数 changgeThumb操作,$0,匹配整个img代码,$1匹配出图片url地址

?

?

protected static function changeThumb($old,$path){
       $width = 580;
        //传递过来的字符串有转义,去掉
       $old = str_replace('\"','"', $old);
       //本身自带的thumb函数,不陌生
       $new = str_replace($path, thumb($path,$width,0), $old);
      return  $new;
}

?好了,这样可以看看你页面中的图片是不是都变成缩略图片了,

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn