2011-09-19 49 views
0

我正在使用file_get_contents来读取.html有一个表的文件。这个preg_match_all有什么问题

<table id="someTable" style="width:100%;margin-bottom:0;"> 
    <tr style="display:none;"> 
     <td style="padding-left:25px;">Some text</td> 
    </tr> 
    <tr style="display:none;"> 
     <td style="padding-left:25px;">another text</td> 
    </tr> 
</table> 

当我使用preg_match_all读取表,我什么也没得到,当我数$matches[1]

preg_match_all('/<table id="someTable" style="width:100%;margin-bottom:0;">(.*)<\/table>/', $html, $matches); 
$co = count($matches[1]); 
+3

寻找用正则表达式解析HTML是几乎可以肯定不是要走的路。你想要达到什么目标? – lonesomeday

回答

1

添加改性剂s到您的preg_match。

preg_match_all('/<table id="someTable" style="width:100%;margin-bottom:0;">(.*)<\/table>/s', $html, $matches); 

http://ideone.com/3w0K2