简单的 HTML DOM 标签选择问题

simple HTML DOM tag selecting issue

我有这个HTML:

  <div class="price" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
        <small class="old-price">Stara cena: 1.890 RSD</small>
        <span>Ušteda: <strong>1.000 RSD</strong></span>
        <h5>890 <em>RSD</em>    
             <div class="tooltip"><p>Cene sa popustom uz gotovinsko plaćanje za online porudžbine</p></div>
        </h5>
        <span style="display:none" itemprop="priceCurrency" content="RSD"></span>
        <span itemprop="price" content="890.00"></span>
    </div>

我正在通过这样的标签收集价格:

foreach($html->find('span[itemprop=price]')  as $element) {
     $niz['price'][] = $element->content;
}

现在我需要从小标签中收集文本(如果它不存在,那么我需要数组中的空字符串):<small class="old-price">Stara cena: 1.890 RSD</small>

所以我需要这样的东西:

if($html->find('small[class=old-price]',0))
{
    $niz['oldprice'][] = $element->innertext;
}else{
    $niz['oldprice'][] = '';
}

问题是我只得到数组中 class=old-price 的元素,而不是一个空字符串。

如有任何建议,我们将不胜感激。

您好,请问可以使用代码吗

foreach($html->find('small[class=old-price]')  as $element) {
    if($element->plaintext)
    {
         $niz['oldprice'][] = $element->plaintext;
    }else{
         $niz['oldprice'][] = '';
    }
}