【发布时间】:2016-10-30 03:47:49
【问题描述】:
我有 html 表,我想从该表中创建数组
$html = '<table>
<tr>
<td>satu</td>
<td>dua</td>
</tr>
<tr>
<td>tiga</td>
<td>empat</td>
</tr>
</table>
我的数组必须是这样的
array(
array(
"satu",
"dua",
),
array(
"tiga",
"empat",
)
)
我已经尝试了下面的代码,但无法得到我需要的数组
$crawler = new Crawler();
$crawler->addHTMLContent($html);
$row = array();
$tr_elements = $crawler->filterXPath('//table/tr');
foreach ($tr_elements as $tr) {
// ???????
}
【问题讨论】:
-
您是否检查过此链接,其中包含完整的详细信息symfony.com/doc/current/components/dom_crawler.html
-
是的。我有。,我只是无法理解爬虫在 foreach 中是如何工作的。,
-
第一个代码块中的 HTML 缺少单引号。错字?
-
不,这只是例子。
标签: php arrays symfony domcrawler