0

I have this html

<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>

I'm need get "1,99 €", but the id 'product-price-326' is generating random numbers. How to find 'product-price-*'? I'm trying

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

and

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

but it doesn't work.

user2289809
  • 53
  • 1
  • 1
  • 9

4 Answers4

3

As per my comment, here's what you need to do:

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

^= means starts with.

Community
  • 1
  • 1
D4V1D
  • 5,805
  • 3
  • 30
  • 65
2

I am not sure what $preke is, but if it's a DOM selector that supports proper class selectors you can use

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

or

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

The ^= tells it to look for elements that has an ID starting with "product-price" and the *= tells it to look for elements that has an ID that contains "product-price".

Chris Brand
  • 1,962
  • 16
  • 9
1

Try Like This Might Be Works

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

why not to get it using class?

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

this will get you 1,99 €

Mubin
  • 4,325
  • 5
  • 33
  • 55