<div id=\"list-new\">.+?<\/tr>\s+<tr>(?:\s+<td.+?>(.+?)<\/td>){6}
大家看看我的这个正则为什么匹配的都是最后一个<td>的值呢?为什么没有把匹配的值一个个获取呢?

解决方案 »

  1.   

    <?
    $str='<div id="list-new"> 
    <table> 
    <tr> 
    <th class="edit">ID </th> 
    <th class="edit">name </th> 
    <th class="edit" style="width:70px">title </th> 
    <th class="edit">content </th> <th class="edit" style="width:100px">time </th> 
    <th class="edit" style="width:220px">desc </th> 
    </tr> <tr> 
    <td class="edit"> <a href="http://abc.com/aa.php?id=777" target="_blank">7777777777 </a> </td> 
    <td class="edit">10 </td> 
    <td class="edit" style="width:70px">你好吗 </td> 
    <td class="edit">vip </td> <td class="edit" style="width:100px">2008-09-10 11:13 </td> 
    <td class="edit" style="width:220px">OK </td> 
    </tr> <tr> 
    <td class="edit"> <a href="http://abc.com/getuser.do?id=333333333333" target="_blank">3333333333333 </a> </td> 
    <td class="edit">120 </td> 
    <td class="edit" style="width:70px">sisisi </td> 
    <td class="edit">abvc </td> <td class="edit" style="width:100px">2008-09-10 12:12 </td> 
    <td class="edit" style="width:220px">很好啊 </td> 
    </tr> 
    </table> ';
    $reg = '/<tr>(?:\s*<td.*?>(.+?)<\/td>\s*)(?:\s*<td.*?>(.+?)<\/td>\s*)(?:\s*<td.*?>(.+?)<\/td>\s*)(?:\s*<td.*?>(.+?)<\/td>\s*)(?:\s*<td.*?>(.+?)<\/td>\s*)(?:\s*<td.*?>(.+?)<\/td>\s*)<\/tr>/is';
    preg_match_all($reg, $str, $res);
    print_r($res);
    ?>
      

  2.   

    这么匹配的html代码,为什么不尝试dom$str='<div id="list-new"> 
    <table> 
    <tr> 
    <th class="edit">ID </th> 
    <th class="edit">name </th> 
    <th class="edit" style="width:70px">title </th> 
    <th class="edit">content </th> <th class="edit" style="width:100px">time </th> 
    <th class="edit" style="width:220px">desc </th> 
    </tr> <tr> 
    <td class="edit"> <a href="http://abc.com/aa.php?id=777" target="_blank">7777777777 </a> </td> 
    <td class="edit">10 </td> 
    <td class="edit" style="width:70px">你好吗 </td> 
    <td class="edit">vip </td> <td class="edit" style="width:100px">2008-09-10 11:13 </td> 
    <td class="edit" style="width:220px">OK </td> 
    </tr> <tr> 
    <td class="edit"> <a href="http://abc.com/getuser.do?id=333333333333" target="_blank">3333333333333 </a> </td> 
    <td class="edit">120 </td> 
    <td class="edit" style="width:70px">sisisi </td> 
    <td class="edit">abvc </td> <td class="edit" style="width:100px">2008-09-10 12:12 </td> 
    <td class="edit" style="width:220px">你好吗 </td> 
    </tr> 
    </table>
    </div>';$str = utf8_encode($str);
    $dom = simplexml_load_string($str);
    echo utf8_decode(htmlspecialchars($dom->table[0]->tr[1]->asXML()));
      

  3.   

    $search = array( 
       '@<[\/\!]*?[^<>]*?>@si',            // Strip out HTML tags 
       '@&nbsp;@' 
      

  4.   

    preg_match("/<td.*?>(.+?)<\/td>/",$text,$matches);
    print_r($matches[1]);
      

  5.   

    preg_match_all("/ <td.*?>(.+?) <\/td>/",$text,$matches); 
    print_r($matches[1]);