A5下载 - 努力做内容最丰富最安全的下载站!

A5站长下载站

当前位置:A5下载 > 源码技巧 > 父类数据 > php preg_replace过滤img宽高

php preg_replace过滤img宽高

时间:2015-05-30 11:17作者:sa人气:46

在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%">';

}

?>

 

标签php,preg,replace,过滤,img,宽高,wap

相关下载

查看所有评论+

网友评论

网友
您的评论需要经过审核才能显示

公众号