提取字符串中所有src图片的地址 或清空

来源:互联网 发布:人工智能技术手册 编辑:程序博客网 时间:2024/05/14 14:34




提取

 /**     * 提取字符串中图片url地址     * @param type $str     * @return type     */    function getimgs($str) {        $reg = '/((http|https):\/\/)+(\w+\.)+(\w+)[\w\/\.\-]*(jpg|gif|png)/';        $matches = array();        preg_match_all($reg, $str, $matches);        foreach ($matches[0] as $value) {            $data[] = $value;        }        return $data;    }


清空

preg_replace('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', '', $str)


原创粉丝点击