本帖最后由 songle912 于 2009-08-18 18:25:05 编辑

解决方案 »

  1.   


    $str=<<<H
    123 <p>abc <img border="0" src="images1.jpg"/> def <img src=images2.jpg style="border:none;"> hhh <img border='0' src='images3.jpg' style="border:none;" />hehe </p>haha
    H;
    preg_match_all("/<img.[^>]*>/i",$str,$m);
    print_r(array_map("htmlentities",$m[0]));
      

  2.   

    楼上的感谢了。你写的正则我看的懂,肯定不行的,看一下我下面的说明,属性有单引号,双引号,没引号的区别。src前后还可能有其他属性。
      

  3.   


    $str='123 <p>abc <img border="0" src="images1.jpg"/> def <img src=images2.jpg style="border:none;"> hhh <img border=\'0\' src=\'images3.jpg\' style="border:none;" />hehe </p>haha';
    if(preg_match_all("(<img[^>]*>)", $str, $matches)){
    foreach($matches[0] as $m){
    echo htmlentities($m)."<br />";
    }
    }else{
    echo "Not found!";
    }
      

  4.   

    我也觉得你不会扔个100分问这么简单的问题,但问题是,你要取什么内容?
    取img标签src属性的值 or anything?
      

  5.   

    我结果希望是: <img border="0" src="images1.jpg"/><img src=images2.jpg style="border:none;"><img border='0' src='images3.jpg' style="border:none;" />
    当然形式如何无所谓的,数组什么的都可以 
      

  6.   

    你自己试一下,并且仔细看看,你的结果是<img src="<img border=&quot;0&quot; src=&quot;images1.jpg&quot;/><br /><img src=images2.jpg style=&quot;border:none;&quot;><br /><img border=&#39;0&#39; src=&#39;images3.jpg&#39; style=&quot;border:none;&quot; /><br />"/>
      

  7.   

    现在要提取其中的img标签的所有内容,结果希望是: <img border="0" src="images1.jpg"/> <img src=images2.jpg style="border:none;"> <img border='0' src='images3.jpg' style="border:none;" />这上面是你的原话啊?你要的不就是这个么?我的出来后就是<img border="0" src="images1.jpg"/>
    <img src=images2.jpg style="border:none;">
    <img border='0' src='images3.jpg' style="border:none;" />啊..哪里不符合标准了??把br去掉后就和你要的完全一模一样了啊.要不你说详细点你到底要什么吧.......
      

  8.   

    难道你是因为那些&quot;之类的???那你用这个代码吧
    $str='123 <p>abc <img border="0" src="images1.jpg"/> def <img src=images2.jpg style="border:none;"> hhh <img border=\'0\' src=\'images3.jpg\' style="border:none;" />hehe </p>haha';
    if(preg_match_all("(<img[^>]*>)", $str, $matches)){
        foreach($matches[0] as $m){
            echo $m;
            }
        }else{
            echo "Not found!";
            }然后你再查看源代码`保证对`绝对和你上面写的一模一样
      

  9.   

    $str='123 <p>abc <img border="0" src="images1.jpg"\/> def <img src=images2.jpg style="border:none;"> hhh <img border=\'0\' src=\'images3.jpg\' style="border:none;" \/>hehe <\/p>haha';
    preg_match_all('/<img\s+[^>]*>/is',$str,$results);
    print_r($results);楼主要么就是没把问题描述清楚。楼上包括我这个的正则跟你给出的要取的结果一样。你要取出所有img标签包括属性,跟你里面使用的是单引号或双引号,结尾是>或/>没关系。用正则只要描述好从<img开头到结尾>的这个范围就可以了。
      

  10.   


    preg_match_all('/<img .*jpg\"\/\>|none\"\>|none\; \/\>/i',$str, $arr);楼主试试这个,没测试,
      

  11.   

    http://topic.csdn.net/u/20080411/09/16ea750b-c5ca-4573-93ae-5b8f330d782c.html