<tr onMouseOver="overCell(this);" onMouseOut="outCell(this);"><td width="30%" class=style2><a href="/products/50-00-0.htm" class=blue //onclick="blur()">
CAS#
</a></td><td width="70%" class=style2>
化学名
</td></tr>
<tr onMouseOver="overCell(this);" onMouseOut="outCell(this);"><td width="30%" class=style2><a href="/products/50-00-0.htm" class=blue //onclick="blur()">
CAS#
</a></td><td width="70%" class=style2>
化学名
</td></tr>
<tr onMouseOver="overCell(this);" onMouseOut="outCell(this);"><td width="30%" class=style2><a href="/products/50-00-0.htm" class=blue //onclick="blur()">
CAS#
</a></td><td width="70%" class=style2>
化学名
</td></tr>
求助一个正则表达式,将表格中的CAS#和化学名提取到一个二维数组中,谢谢正则表达式

解决方案 »

  1.   

    $s=<<<html
    <tr onMouseOver="overCell(this);" onMouseOut="outCell(this);"><td width="30%" class=style2><a href="/products/50-00-0.htm" class=blue //onclick="blur()">
        CAS#
    </a></td><td width="70%" class=style2>
        化学名
    </td></tr>
    <tr onMouseOver="overCell(this);" onMouseOut="outCell(this);"><td width="30%" class=style2><a href="/products/50-00-0.htm" class=blue //onclick="blur()">
        CAS#
    </a></td><td width="70%" class=style2>
        化学名
    </td></tr>
    <tr onMouseOver="overCell(this);" onMouseOut="outCell(this);"><td width="30%" class=style2><a href="/products/50-00-0.htm" class=blue //onclick="blur()">
        CAS#
    </a></td><td width="70%" class=style2>
        化学名
    </td></tr>
    html;
    preg_match_all('/>([^>]+)<\/a><\/td><td width="70%" class=style2>(.+)<\/td>/isU',$s,$m);
    print_r($m);
      

  2.   


    谢谢jordan的回复,这段代码能够很好的运行,但是因为获取过后的网页代码我编辑过,实际的网页格式是
    <tr onMouseOver="overCell(this);" onMouseOut="outCell(this);">
    <td width="30%" class=style2>
    <a href="/products/50-00-0.htm" class=blue onclick="blur()">50-00-0</a>
    </td>
    <td width="70%" class=style2>
    Formaldehyde
    </td>
    </tr><tr onMouseOver="overCell(this);" onMouseOut="outCell(this);">
    <td width="30%" class=style2>
    <a href="/products/50-01-1.htm" class=blue onclick="blur()">50-01-1</a>
    </td>
    <td width="70%" class=style2>
    Guanidine hydrochloride
    </td>
    </tr>我使用jordan的正则表达式获取到的数组是空的,请问是怎么回事,本人是正则表达式菜鸟,请多多包涵谢谢
      

  3.   

    以解决,将字符串中所有换行去除就可以了,谢谢jordan