xiao Posted April 4, 2008 Share Posted April 4, 2008 Hi, If I have a string like this: $title = "Abit IL9 Pro (Retail, RAID, Gb-LAN, Sound, ATX) - €54,57"; How do I use preg_match to get 54,57? I got this much: preg_match('/- €/si', $title, $price); But I'm not too good with regex. Quote Link to comment https://forums.phpfreaks.com/topic/99531-getting-valuta-from-string-with-preg_match/ Share on other sites More sharing options...
craygo Posted April 4, 2008 Share Posted April 4, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/99531-getting-valuta-from-string-with-preg_match/#findComment-509165 Share on other sites More sharing options...
xiao Posted April 4, 2008 Author Share Posted April 4, 2008 Yea, thanks so far. But it has to work for prices <10 and >99 too That's where I kinda got confused too. Is there maybe a function I can use to just subtract the last part? like this: function($string, " - €") Quote Link to comment https://forums.phpfreaks.com/topic/99531-getting-valuta-from-string-with-preg_match/#findComment-509171 Share on other sites More sharing options...
craygo Posted April 4, 2008 Share Posted April 4, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/99531-getting-valuta-from-string-with-preg_match/#findComment-509173 Share on other sites More sharing options...
xiao Posted April 4, 2008 Author Share Posted April 4, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/99531-getting-valuta-from-string-with-preg_match/#findComment-509185 Share on other sites More sharing options...
laffin Posted April 4, 2008 Share Posted April 4, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/99531-getting-valuta-from-string-with-preg_match/#findComment-509214 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.