去除img標籤函數

 

須要去除一個長字符串中的img標籤,網上找到了這個代碼試試看,確實是有效的。代碼以下:php

<?php
function strip_tags_img($string='')
{
    $pattern= '/<img[\s\S]*?src\s*=\s*[\"|\'](.*?)[\"|\'][\s\S]*?>/';
    preg_match_all($pattern,$string,$match);
    if($match)
    {
        if(!empty($match[0]))
        {
            foreach($match[0] as $v)
            {
                $string=str_replace($v,'',$string);
            }
        }
    }
    return $string;
}
?>

暫時沒時間研究具體還有沒有改進方式,先把這個記錄下來當筆記。spa

相關文章
相關標籤/搜索