Page 1 of 1
Simple Problem!
Posted: Thu Aug 19, 2004 11:07 am
by Joe
OK I have posted something fairly similar to this before, however a couple of changes have been made. I am looking for a regular expression which could be used to take the number out of the braces. For example (£12.00) would become £12.00.
Any help appreciated here!
Joe

Posted: Thu Aug 19, 2004 11:13 am
by feyd
Code: Select all
$result = preg_replace('#\(([^\)]+?)\)#', '$1', $text);
Posted: Thu Aug 19, 2004 11:18 am
by dull1554
feyd's answer is better.......
try something like this
Code: Select all
<?php
$var = preg_split ("/[()]+/", "(£12.00)");
echo $var[1];
?>
Posted: Thu Aug 19, 2004 11:20 am
by Joe
Thanks feyd and dull much appreciated. Regular expressions is the one thing I need to have a look at. I noticed in the shop that there was actually huge books related on that one subject.
Posted: Thu Aug 19, 2004 11:47 am
by Lord Sauron
Why not simply using this one:
Code: Select all
<?php
$var = (€12.00);
$changeVar = array(")"=>"" , "("=>"");
$var = strtr($var,$changeVar);
?>
Antonie
Posted: Thu Aug 19, 2004 11:57 am
by Joe
Well thanks for that. One more question though, is it possible for me to take the number out if there is text in the line. For example:
product1(£12.00)
Would become:
£12.00
Posted: Thu Aug 19, 2004 12:00 pm
by feyd
Code: Select all
<?php
$result = preg_replace('#.*?\(([^\)]+?)\).*#s', '$1', $text);
?>
Posted: Thu Aug 19, 2004 12:06 pm
by Joe
Thanks feyd. Worked perfect. Problem solved.
