1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

some easy help with regex?

Discussion in 'PHP' started by roadrunner12, Jan 19, 2009.

  1. #1
    Hey guys,
    SEMrush
    I need a regex to remove everything before the price:

    314 15 Up to 4 $142.00

    Keep in mind that whatever comes before the price won't be the same thing everytime.

    Can anyone help? Thanks!
     
    roadrunner12, Jan 19, 2009 IP
    SEMrush
  2. lp1051

    lp1051 Well-Known Member

    Messages:
    163
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Hey,
    can be before price another '$' sign?? If not, you can use e.g.
    $string="314 15 Up to 4 $142.00";
    preg_match('/^[^$]+(\$\d+\.\d+)$/', $string, $price);
    then you have price in $price[1]. It also counts, that price format is always '$numbers.numbers'
    Hope it helps
     
    lp1051, Jan 20, 2009 IP
  3. WPGLamour

    WPGLamour Member

    Messages:
    30
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    45
    #3
    You can also use:
    $price = "314 15 Up to 4 $142.00";
    $price = explode("$", $price);
    $price[0] will echo 314 15 Up to 4
    and $price[1] will echo 142.00
     
    WPGLamour, Jan 20, 2009 IP