Jump to content

Getting valuta from string with preg_match


xiao

Recommended Posts

holy crap I actually did a regex!!!

 

$title = "Abit IL9 Pro (Retail, RAID, Gb-LAN, Sound, ATX) - €54,57";
preg_match('/[0-9][0-9],[0-9][0-9]/si', $title, $price);
print_r($price);

 

I'm sure my code is probably primitive but it works Only problem it doesn't work for prices in the hundreds but I will work on that. :)

 

Ray

 

 

got it

 

$title = "Abit IL9 Pro (Retail, RAID, Gb-LAN, Sound, ATX) - €54322,57322";
preg_match('/[0-9]+,[0-9]+/si', $title, $price);
print_r($price);

 

Ray

 

Would it work like this?

preg_match('/- €[0-9]+,[0-9]+/si', $title, $price);

 

EDIT: oh no, sorry, I would get more then just the numbers like this. Oops :D

than continue using the options preg_match offers :)

$title = "Abit IL9 Pro (Retail, RAID, Gb-LAN, Sound, ATX) - €54322,57322";
preg_match('/- € (\d+,\d+)/si', $title, $price);
print_r($price);

 

$price[0] will display the whole match string as u have seen already

$price[1] will display the price value

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.