jmurch Posted September 17, 2008 Share Posted September 17, 2008 I have a value that as is cannot be manipulated arithmatically. The values are in the format '$x,xxx.xx'. Is there a built in PHP function to strip out the $ and the ',' so I can treat this as a integer? Quote Link to comment Share on other sites More sharing options...
Goldeneye Posted September 17, 2008 Share Posted September 17, 2008 You could just use str_replace, like so: <?php $text = str_replace('$', '', $text); $text = str_replace(',' '', $text); ?> Quote Link to comment Share on other sites More sharing options...
jmurch Posted September 17, 2008 Author Share Posted September 17, 2008 Thanks Goldeneye. Quote Link to comment Share on other sites More sharing options...
Caesar Posted September 17, 2008 Share Posted September 17, 2008 Or preg_replace... <?php $str = '$1,500.00'; $a = array('/\$/','/,/'); $B = array('',''); $number = preg_replace($a,$b,$str) * 2; echo $number; ?> Quote Link to comment 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.