简体   繁体   English

Preg_match_all —抓取之间的所有html代码(数据) <table></table>

[英]Preg_match_all — grab all html code(data) between <table></table>

I want to grab all html between: 我想抓住之间的所有html:

<table cellpadding="0" cellspacing="0" border="0" class="list" width="100%">
.
.
.
.
</tbody>

preg_match_all('XXXXXXXXXX', $this->markup, $links);

In general, I'd recommend to use DomDocument instead of a regular expression too. 通常,我建议也使用DomDocument而不是正则表达式。 But DomDocument requires some extra hussle in this case, because OP wants the HTML code, not only the nodeValue(s). 但是在这种情况下,DomDocument需要一些额外的麻烦,因为OP不仅需要nodeValue,还需要HTML代码。 (Anyway, for a DomDocument-based approach you could use some "workaround" like this (to get the table's contents incl. HTML.)) (反正,对于基于的DomDocument的方法,你可以使用一些“变通”像这样 (得到表的内容含HTML))

That being said, here's the regex you asked for: 话虽如此,这是您要的正则表达式:

$html = '<table cellpadding="0" cellspacing="0" border="0" class="list" width="100%">' .
        '<tr><td>Lorem</td><td>Ipsum</td></tr>' . 
        '</table>';

preg_match_all('/<table.*?>(.*?)<\/table>/si', $html, $matches); 

var_dump($matches[1][0]); // string(37) "<tr><td>Lorem</td><td>Ipsum</td></tr>"

您应使用DomDocument之类的东西,而不要使用正则表达式进行解析。

Use phpQuery for this operation. 使用phpQuery进行此操作。 PhpQuery has syntax like jQuery, and it's simply for understanding PhpQuery具有类似于jQuery的语法,仅用于理解

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM