Page 1 of 1

Regular Expression Help!

Posted: Mon Aug 16, 2004 10:58 am
by Joe
I was wondering how I can go about taking the price from a sentance. For example if the sentance go's like:

DVD Player (£70.00)

How would I take the price 70.00 without the currency symbol. I know regular expressions should be used here but I can't seem to work out the pattern.

Any help appreciated.


Joe 8)

Posted: Mon Aug 16, 2004 1:01 pm
by markl999
A few ways to do it, here's one (i think ;))

Code: Select all

<?php
$string = 'DVD Player (£70.00)';
preg_match('#£([0-9\.]*)#', $string, $matches);
echo $matches[1];
?>

Posted: Tue Aug 17, 2004 3:11 pm
by Joe
Thanks mark but I couldn't seem to get that to work. Any other ways possible?.

Posted: Wed Aug 18, 2004 5:20 am
by markl999
That way worked fine for me, so your $string must be in a different format. Can you post what $string would look like in your case?