PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Joe
Forum Regular
Posts: 939 Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow
Post
by Joe » Mon Aug 16, 2004 10:58 am
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
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Mon Aug 16, 2004 1:01 pm
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];
?>
Joe
Forum Regular
Posts: 939 Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow
Post
by Joe » Tue Aug 17, 2004 3:11 pm
Thanks mark but I couldn't seem to get that to work. Any other ways possible?.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Wed Aug 18, 2004 5:20 am
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?