2015-07-21 37 views
0

我有这个网站腓简单的HTML DOM解析器查找字符串的任何字符

<div class="price-box"> 

       <p class="old-price"> 
      <span class="price-label">This:</span> 
      <span class="price" id="old-price-326"> 
       8,69 €    </span> 
     </p> 

        <p class="special-price"> 
      <span class="price-label">This is:</span> 
      <span class="price" id="product-price-326"> 
       1,99 €    </span> <span style="">/ 6.87 </span> 
     </p> 


    </div> 

我需要得到“1,99€”,但ID为“产品价格-326”是生成随机数。如何找到'product-price- *'?我想

foreach($preke->find('span[id="product-price-[0-9]"]') as $div) 

foreach($preke->find('span[id="product-price-"]') as $div) 

,但它不工作。

+4

尝试'$ preke-> find('span [id^=“product-price - ”]')'。 – D4V1D

+0

重复? http://stackoverflow.com/questions/13525124/simple-html-dom-wildcard-in-attribute – Webice

+0

它的工作。谢谢D4V1D – user2289809

回答

1

我不知道什么$preke是的,但如果它是支持正确的类选择一个DOM选择器可以使用

$preke->find('span[id^="product-price"]') 

$preke->find('span[id*="product-price"]') 

^=告诉它来寻找元素具有以“产品价格”开头的ID并且*=告诉其寻找具有包含“产品价格”的ID的元素。

+0

感谢您的解释。有用。 – user2289809

0

为什么不使用class

echo $preke->find('.special-price', 0)->find('.price', 0)->plaintext; 

这将让你1,99 €

+0

谢谢,它也有效,但现在我得到了:“这是:1,99€/ 6.87” – user2289809

1

尝试像这可能是作品

foreach($preke->find('span[id^="product-price-"]') as $div) { /* Code */ }