本帖最后由 vgy12304 于 2010-02-20 13:34:20 编辑

解决方案 »

  1.   


    $str = <<<str
    <DIV style=\"POSITION: absolute; TOP: 19px; LEFT: 25px\" id=idDrag485 class=idfrom ondblclick=deldiv(485)> 
    <DIV id=idHandle485 class=idtest ondblclick=deldiv(485)> 
    <TABLE class=control_contect_li cellSpacing=0 cellPadding=0 width=\"100%\"> 
    <TBODY> <TR> <TD width=\"30%\" align=right>联系人: </TD> <TD width=\"70%\"> <INPUT class=red size=20 name=relname {Require} style="color:#000000;"> </TD> </TR> </TBODY> </TABLE> 
    </DIV> 
    </DIV> <DIV style=\"POSITION: absolute; TOP: 193px; LEFT: 53px\" id=idDrag267 class=idfrom ondblclick=deldiv(267)> 
    <DIV id=idHandle267 class=idtest ondblclick=deldiv(267)> 
    <TABLE class=control_contect_li cellSpacing=0 cellPadding=0 width=\"100%\"> 
    <TBODY> <TR> <TD width=\"30%\" align=right>性别: </TD> <TD width=\"70%\"> <INPUT class=black value={Require} type=radio name=sex> </TD> </TR> </TBODY> </TABLE> 
    </DIV> 
    </DIV> <DIV style=\"POSITION: absolute; TOP: 70px; LEFT: 24px\" id=idDrag456 class=idfrom ondblclick=deldiv(456)> 
    <DIV id=idHandle456 class=idtest ondblclick=deldiv(456)> 
    <TABLE class=control_contect_li cellSpacing=0 cellPadding=0 width=\"100%\"> 
    <TBODY> <TR> <TD width=\"30%\" align=right>兴趣: </TD> <TD width=\"70%\"> <INPUT class=blue value={Require} type=checkbox name=xingqu> </TD> </TR> </TBODY> </TABLE> 
    </DIV> 
    </DIV> 
    str;echo $str;
    echo '<hr>';preg_match_all('/\<div style=\\\\\"([^\"]+)\\\\\" id=[^\>]+\>.*?\<div id=idH([^\s]+).+?\<input.+?name=([^\s\>]+).*?\>.+?\<\/div\>.*?\<\/div\>/is', $str, $matches);print_r($matches);
      

  2.   

    谢谢楼上的回复,你的这个正则不太好用哦,得不到结果哦
    只有个空数组
    Array
    (
        [0] => Array
            (
            )
     
        [1] => Array
            (
            )
     
        [2] => Array
            (
            )
     
        [3] => Array
            (
            )
     
    )
      

  3.   

    这个问题我已经解决了,2楼的代码是正确的,问题出在浏览器版本上面id6,7,8输出的html数据流居然是不同的,所有贪婪匹配会因为不同的浏览器而失效,
    id6输出顺序是<div class=XXX id=XXX style=XXX
    ie8输出顺序是<div style=XXX id=XXX 
    有兴趣研究版本兼容性的朋友,不妨试试
    目前是用的抓取元素的方式解决的,把代码发上来,有兴趣的哥们看看
    $str=$_POST["htmlcode"];
    $str=str_replace("\\","",$str);
    preg_match_all('/style=\"([^"]*)/is',$str,$arrPos);
    preg_match_all('/idDrag([^\s>]+)/is',$str,$arrIds);
    preg_match_all('/name=([^\s>]+)/is',$str,$arrNames);