[phpstudy]php 正则表达式提取图片url程序

更新时间:2017-09-08    来源:正则表达式    手机版     字体:

【www.bbyears.com--正则表达式】

我想对 html 的图片进行提取.

 代码如下

如上地址. 我想全部提取出来 但是包含"ico" 的地址 忽略. 求正则 , 就是有些图片 提取.有些不提取.

例子:

 代码如下 ]*?srcs*=s*("|")(.*?)\1[^>]*?/?s*>

经改进后..

正确解答如下

 代码如下

//

实例

 代码如下

//要替换的内容   
    $content = "



";

    //提取图片路径的src的正则表达式
    preg_match_all("/]+>/isU",$content,$matches);

            $img = "";
            if(!empty($matches)) {
            //注意,上面的正则表达式说明src的值是放在数组的第三个中
                $img = $matches[2];
            }else {
                $img = "";
            }
            if (!empty($img)) {
                $img_url = "http://".$_SERVER["SERVER_NAME"];

                $patterns= array();
                $replacements = array();

                foreach($img as $imgItem){

                $final_imgUrl = $img_url.$imgItem;
                $replacements[] = $final_imgUrl;

                $img_new = "/".preg_replace("///i","/",$imgItem)."/";
                $patterns[] = $img_new;

                }

                //让数组按照key来排序
                ksort($patterns);
                ksort($replacements);

                //替换内容
                $vote_content = preg_replace($patterns, $replacements, $content);

本文来源:http://www.bbyears.com/aspjiaocheng/35443.html

猜你感兴趣

热门标签

更多>>

本类排行