【发布时间】:2021-02-01 02:40:54
【问题描述】:
我正在使用 PHP 简单的 dom 解析器,我应该如何在其中插入额外的实体?像 $html 包含
<table class="tb">..</table>
<table>..</table>
<table>..</table>
我知道如何选择dom,比如$html->find('div[class="tb"][1]');
但是如何在它之后连接新的div?就像我想把广告 btw 表。
【问题讨论】:
我正在使用 PHP 简单的 dom 解析器,我应该如何在其中插入额外的实体?像 $html 包含
<table class="tb">..</table>
<table>..</table>
<table>..</table>
我知道如何选择dom,比如$html->find('div[class="tb"][1]');
但是如何在它之后连接新的div?就像我想把广告 btw 表。
【问题讨论】:
如果你还想要简单的例子:
$banner = '<div class="ads">blablabla</div>';
$tables = $html->find('table');
foreach($tables as $table){
$table->outertext .= $banner;
}
或者:
$html->find('div[class="tb"][1]').outertext .= '<div class="ads">blablabla</div>';
在阅读 here 的文档后制作的 (:
【讨论】: