我有一个HTML表格,格式如下:正如你所看到的,第一个标题1有一个与之相关的行1。第二个标题2有两行 - 第2行,第3行与它关联。标题3具有与其相关的第4行,第5行,第6行。PHP:简单的HTML Dom解析器 - 解析带有标题/不均匀正文行的HTML表格
<table>
<thead>
<tr>
<th>Header 1</th>
</tr>
</thead>
<tbody>
<tr>
<td>
Row 1
</td>
</tr>
</tbody>
<thead>
<tr>
<th>Header 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>
Row 2
</td>
</tr>
<tr>
<td>
Row 3
</td>
</tr>
</tbody>
<thead>
<tr>
<th>Header 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>
Row 4
</td>
</tr>
<tr>
<td>
Row 5
</td>
</tr>
<tr>
<td>
Row 6
</td>
</tr>
</tbody>
我想使用的PHP简单的HTML DOM解析器得到以下数据:
Header 1, Row 1
Header 2, Row 2, Row 3
Header 3, Row 4, Row 5, Row 6
当我使用的解析器来获取标签,所有的人都存储在一个数组。当我执行foreach循环时,所有其他标记都存储在另一个数组中。我在循环时如何保留标题与行的关联?
为什么不使用内置的DOMDocument接口? – trincot
请显示您的代码。你指的是哪个foreach? – Nima