A5下载文章资讯

分类分类

php preg_replace过滤img宽高

2015-05-30 11:17作者:sa

在wap开发中,获取文章内容的时候,里面的图片都设置宽和高,这样在手机里就不会等比缩小,那怎么用php代码过滤img的宽高呢?

代码如下:

<?php

$str='<img title="你有多久没回家了?看完好心塞" border="0" src="http://zz.bcty365.com/content/uploadfile/201501/74d31420723044.jpg" width="446" height="280">';

echo content_strip($str);

function content_strip($content) {

$content = preg_replace('/<img[^>]*src=['"]?([^>'"s]*)['"]?[^>]*>/ie', "wap_img('$1')", $content);

return $content;

}

function wap_img($url) {

return '<img src="'.$url.'" width="100%">';

}

?>

 

展开全部

相关

说两句网友评论
    我要跟贴
    取消