0

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?

2
Contributors
5
Replies
7
Views
6 Years
Discussion Span
Last Post by kekkaishi
0

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

0

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.

Edited by kekkaishi: n/a

0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.