如何使用当前的php代码从表单输入中删除$和逗号? [英] How to remove $ and comma from form input using current php code?

查看:94
本文介绍了如何使用当前的php代码从表单输入中删除$和逗号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我输入格式的示例

<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表类型设置为:decimal(16,2)

Mysql table type is set to : decimal(16,2)

这是我的问题:

例如:

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

输出格式:625

这意味着它不会以货币正确格式保存到表中,逗号到sql表后也不会保存.应该是这样的:625695295.00

It means, it won't save into table as currency correct format, it won't save after comma into sql table. It should be something like this: 625695295.00

当数据发布到mysql表时,如何删除那些逗号和美元符号?

How to remove it those commas and dollar sign when data is posting to mysql table?

这是我的邮政编码:

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

谢谢.

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

SOLUTION: PROBLEM SOLVED!! SPECIAL THANKS TO chris85 Here we go:

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

推荐答案

这是一种JavaScript方法,可用于去除US$,空格和逗号.

Here's a javascript approach you could use to strip the US$, whitespaces, and commas.

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

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

我会用PHP做到这一点.

I'd do this in PHP though.

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

这篇关于如何使用当前的php代码从表单输入中删除$和逗号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆