<div>ZxzcZXc</div>
<table id="1"  cellpadding="0" cellspacing="0" mu="http://zhidao.baidu.com/question/172969310.html">
    <tr>
        <td class="f" style="padding-bottom:4px;">
            <font size="3">
                <a href="http://zhidao.baidu.com/question/172969310.html" target="_blank" onmousedown="return c({'fm':'alzd','title':this.innerHTML,'url':this.href,'p1':al_c(this)});">摸<em>你傻</em>是什么_百度知道</a>
            </font><br />
            <font size="-1">
                还有“黑白”...
            </font><br />
            <font size="-1" color="#008000">zhidao.baidu.com/question/172969310.html&nbsp;&nbsp;2010-8-12</font>
        </td>
    </tr>
    <tr>
        <td class="f">
            <p style="margin:0;padding:0;margin-left:1em;">
            </p>
        </td>
    </tr>
</table><br>
<table id="2" cellpadding="0" cellspacing="0" class="result">
    <tr>
        <td class=f>
            <a   href="http://www.douban.com/people/virginiawood/"  target="_blank" >
                <font size="3">烦<em>你傻</em></font>
            </a><br>
            <font size=-1>
            </font>
        </td>
    </tr>
</table>
<span>dddddddddddddd</span>如上面代码(table其实还有更多),需要取出某个链接所在的table的ID值。
不同table里不会存在相同的链接,所以只需要得到一个 id 。RT,求解。

解决方案 »

  1.   


    preg_match_all("/<table[^>]+?id=\"([^\"]+?)\"[^>]+mu=\"([^\"]+)\">/",$ct,$match);
    print_r($match);
    $ct是读入的页面内容
      

  2.   


    只匹配到第一个啊。
    Array ( [0] => Array ( [0] => ) [1] => Array ( [0] => 1 ) [2] => Array ( [0] => http://zhidao.baidu.com/question/1729693100.html ) ) 
      

  3.   

    $str  = "http://www.baidu.com/s?wd=%C4%E3%C9%B5";
    $ct   =file_get_contents($str);preg_match_all("/<table[^>]+?id=\"([^\"]+?)\"[^>]+mu=\"([^\"]+)\">/",$ct,$match1);
    echo '<pre>';
    print_r($match);这次全贴过来了。
      

  4.   

    自己去研究了一下正则,已经搞定了
    preg_match_all("/<table[^>]+id=\"([^\"]+?)\"[^>]*>[\s\S]*?<\/table>/",$str,$match);