2011-09-19 25 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