问题
I want to convert Price format to number only with a php function
Example 1
3,850,000,000 to 3850000000
Example 2
3.850.000.000 to 3850000000
Example 3
3-850-000-000 to 3850000000
回答1:
Why not to use regular expressions? This should do the trick:
$numbers = preg_replace('/[^0-9]/', '', $price);
It's basically telling to match any non-numeric (^
stays for different from) char and then to replace it with nothing.
回答2:
You can also use preg_replace('/\D/', '', $number);
\D
matches all non-digit characters, but also takes into consideration other unicode-defined digits not just 0-9.
回答3:
May be this will helpfull to you
string number_format ( float $number , int $decimals = 0 , string $dec_point = "." , string $thousands_sep = "," )
回答4:
You can use the str_ireplace()
function
For example, replace the characters ","
(case-insensitive) in the string MIVARIABLE
with ""
:
<?php
echo str_ireplace(",", "", MIVARIABLE );
?>
来源:https://stackoverflow.com/questions/34398931/how-to-convert-price-format-to-number-only-with-php