Is there a simple way to extract the money amount from a string using php?
For example, I have $1,419.99
I want to get in return 1419.99
Another example, I have $1,321
I want to get 1321 back.
I know I can manually remove $ and , but is there a way using something like preg_match to grab all the numbers and if any thing after the decimal, grab that as well and just return the number with no , or dollar sign? Seems like a simple solution but for some reason my mind is not wrapping around this.
Checkout NumberFormatter::parseCurrency
Here's the link to PHP documentation for it
yes you can used explode function. Like
$amount = '$1,419.99';
$money = explode('$', $amount);
echo $money[1];
Results: 1,419.99
Hi If you want to use regular expression, you can try the below code
$amount = '$1,419.99';
$amount = preg_replace('/[^.a-zA-Z0-9]/s', '', $amount );
echo $amount;