如何使用当前 php 代码从表单输入中删除 $ 和逗号?

How to remove $ and comma from form input using current php code?

这是我的输入格式示例

<script type="text/javascript" src="http://jquerypriceformat.com/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="http://jquerypriceformat.com/js/jquery.price_format.2.0.js"></script>
<script type="text/javascript" src="http://jquerypriceformat.com/js/ini.js"></script>
<label for="example6">Currency:</label>
<input id="example6" name="example6" value="" type="text">

Mysql table 类型设置为:decimal(16,2)

这是我的问题:

例如:

输入格式:US$ 625,695,295.00

输出格式:625

这意味着,它不会保存为 table 作为货币正确格式,它不会在逗号后保存为 sql table。它应该是这样的:625695295.00

如何在数据 posting 到 mysql table 时删除那些逗号和美元符号?

这是我的 post 代码:

$problem->setExample6($_POST["example6"]);
$_POST["example6"] = $problem->getExample6();

提前致谢。

解决方案:问题已解决!!特别感谢 chris85 开始吧:

   $problem->setExample6(str_replace(array(',', 'US$', ' '), '', $_POST["example6"]));
   $_POST["example6"] = $problem->getExample6();

这是一种 javascript 方法,您可以使用它来去除 US$、空格和逗号。

var string = 'US$ 625,695,295.00';
alert(string.replace(/(US$|\s*|,)/g, ''));

演示:http://jsfiddle.net/8u51grd9/1/

虽然我会在 PHP 中执行此操作。

$_POST["example6"] = str_replace(array(',', 'US$', ' '), '', $_POST["example6"]);