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? Link to comment https://forums.phpfreaks.com/topic/124727-need-to-convert-text-amount-so-i-can-get-a-sum-and-an-average/ 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); ?> Link to comment https://forums.phpfreaks.com/topic/124727-need-to-convert-text-amount-so-i-can-get-a-sum-and-an-average/#findComment-644271 Share on other sites More sharing options...
jmurch Posted September 17, 2008 Author Share Posted September 17, 2008 Thanks Goldeneye. Link to comment https://forums.phpfreaks.com/topic/124727-need-to-convert-text-amount-so-i-can-get-a-sum-and-an-average/#findComment-644273 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; ?> Link to comment https://forums.phpfreaks.com/topic/124727-need-to-convert-text-amount-so-i-can-get-a-sum-and-an-average/#findComment-644274 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.