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.

3
  • 4
    Try $preke->find('span[id^="product-price-"]'). Commented Jul 21, 2015 at 13:26
  • Duplicate? stackoverflow.com/questions/13525124/… Commented Jul 21, 2015 at 13:26
  • it's working. Thanks D4V1D Commented Jul 21, 2015 at 13:29

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

1

Try Like This Might Be Works

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

Comments

0

why not to get it using class?

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

this will get you 1,99 €

1 Comment

Thanks, it works too, but now i'm got: "This is: 1,99 € / 6.87"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.