我需要通过现有值找到元素,我使用简单的html dom解析器,输入html - 可能不完整。 例 HTML:
<div class="params">
<dl class="row param">
<dt class="param_title">Name</dt>
<dd class="param_content">Some name</dd>
</dl>
<dl class="row param">
<dt class="param_title">Sum</dt>
<dd class="param_content">23400</dd>
</dl>
<dl class="row param">
<dt class="param_title">Address</dt>
<dd class="param_content">Here some address</dd>
</dl>
</div>
<div class="params">
<dl class="row param">
<dt class="param_title">Name</dt>
<dd class="param_content">Some name</dd>
</dl>
<dl class="row param">
<dt class="param_title">Address</dt>
<dd class="param_content">Here some address</dd>
</dl>
</div>
PHP:
foreach($html->find('dd[class=param_content]') as $el)
echo $el->innertext . '<hr>';
结果:
Some name
23400
Here some address
-----------------
Some name
Here some address
但是这段代码对我不起作用,我需要输出这样的文字:
Some name
23400
Here some address
-----------------
Some name
Null<-because there is no Sum, write Null, that's what I'm looking for
Here some address