Hi

i have this string:

<div class="col-price">
    <h4>you save</h4>
    
    <span ><span class="currency">$</span>32</span>
    </div>
    <div class="col-price">
    
    <h4>discount</h4>
    <span >52%<span class="persent"></span></span>
    </div>
    
    <div class="col-price last">
    <h4>original price</h4>
    <span ><span class="currency">$</span>62</span>
    
    </div>

i want to be able to find the values of:
you save, discount and original price.
the desierd output: 32, 52, 62

how can i do it with Regular Expressions?

Recommended Answers

All 5 Replies

Why? What is that you are exactly trying to do?

Why? What is that you are exactly trying to do?

I import this string from another site
and in my site i want to extract the values from it

wow :D Assuming that html would remain unchanged, these are the strings I'd focus on.

//to get you save
<h4>you save</h4>
    <span ><span class="currency">$</span>32

//discount
<h4>discount</h4>
    <span >52
//orig. price. 
<h4>original price</h4>
    <span ><span class="currency">$</span>62

Change these to patterns and remember that all the values (32, 52, 62) are groups of numerics.

Good luck.

wow :D Assuming that html would remain unchanged, these are the strings I'd focus on.

//to get you save
<h4>you save</h4>
    <span ><span class="currency">$</span>32

//discount
<h4>discount</h4>
    <span >52
//orig. price. 
<h4>original price</h4>
    <span ><span class="currency">$</span>62

Change these to patterns and remember that all the values (32, 52, 62) are groups of numerics.

Good luck.

Thank's

can anyone point me please to the right pattern?
at least for the first h4?
I would appreciate it very much

Its preferable for you to try on your own first and share your difficulties. However, i will give you an example, a different one, but I hope it is of help to you.

$s = "this is a string and this a currency - $34";
$qs = preg_quote($s); //to avoid special chars like - and $
$ptn = "/".$qs."$(?=([0-9]*))/"; //pattern to find number followed by "this is a string and this a currency - $"
preg_match($ptn, $s, $r); //$r is results array
echo $r[0]; //echos "this is a string and this a currency - $" without "
echo $r[1]; //echos 34

Good luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.