在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%">';
}
?>
新聞熱點
疑難解答