How to convert price format to number only with php?

烈酒焚心 提交于 2019-12-12 03:13:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!