【发布时间】:2013-02-19 15:55:31
【问题描述】:
我想要的是检索特定 <td> 标记之间的 HTML <a> 标记的数量。
这个例子是我所拥有的,但我不知道如何将其余部分放入代码中..
$dom = new DOMDocument();
$dom->loadHTML($text);
$i = 0;
foreach($dom->getElementsByTagName("td") as $node){
//Retrieve every TD tag that have the attribute bgcolor = #0051AB
//<td bgcolor=#0051AB> NODEVALUE </td>
if($node->getAttribute("bgcolor") == "#0051AB"){
$cat[]= $node->nodeValue;
}
//HERE identify every 'a' html tag that are between the $node and the next one!!
//<a href="path">nodeValue</a>
}
例子
<table><tr><td bgcolor=#0051AB>Project 1</td></tr></table>
<a>link1</a>
other tags and text..
<a>Link 2</a>
enter code here
<table><tr><td bgcolor=#0051AB>Project 2</td></tr></table>
codecodecode
<a>link3</a>
codecodecode
我需要的结果:(0 = td nodeValue 的名称,1 = 下一个节点之前的标签数)
Array => (
Array[0] => ([0] => Project1, [1] => 2 ),
Array[1] => ([0] => Project2, [1] => 1 )
)
感谢您的建议。
【问题讨论】:
-
xpath?
//td[@bgcolor="#0051AB"]//a? -
你能澄清一下你在这里说的话吗?
-
能否请您详细说明或分享您的示例 html
-
例子现在有问题