与我之前发布的关于Simple HTML DOM Parser的帖子相关的问题。 这是我的HTML代码:
<div id="header">
<h1>Hello World!</h1>
</div>
<div id="container">
<div id="content">
<p> </p>
</div>
</div>
<div id="footer">
<p>LINK HERE</p>
</div>
我想在页脚的<p>
上插入一个链接。我可以插入一个链接,但问题是,如果在div页脚<p>
之前还有另一个<p>
,链接将插入html代码中的<p>
。它就像它无法识别或无法检测到它只应该在div id = footer中搜索,而不是整个html代码。
这就是我所拥有的:
foreach($html->find('div#footer') as $footer)
{
foreach($footer->find('p') as $p)
{
$footerInnerText = $p->find('p', 0)->innertext;
$theLink = '<a href="index.php" title="" rel="home">'. $footerInnerText. '</a>';
$html->find('p', 0)->innertext = "\n" .$theLink."\n";
}
我也试过这个:
$e = $html->find('div#footer', 0)->find('p', 0);
我在这里缺少什么?
答案 0 :(得分:0)
我发现HTML中的节点有点时髦。我已经看到了一些空白节点等问题。例如在HTML中,空白“”会解析为没有,因为你没有任何真实文本。
是空间所需的代码。
我认为问题可能是由于P的innerHTML被消隐,因此不存在。您是否试过在其中添加任何值,只是随机测试线等?