php – 在USAePay源代码中将ereg_replace转换为preg_replace

我正在使用USAEPay的[可怕] PHP库连接到他们的网关,但是我收到以下错误

Deprecated: Function ereg_replace() is deprecated in …/uSAEpay.PHP on line 320

这对应于以下行:

$this->amount = ereg_replace("[^[:digit:].]", "", $this->amount);

所以,我想用preg_replace切换它.
这就是我的想法:

$this->amount = ereg_replace("/[^[\d].]/", "", $this->amount);

这相当于上面的那个吗?

解决方法:

您希望从表示金额的字符串中删除任何非数字或非句点字符.你可以做:

$this->amount = preg_replace("/[^\d.]/", "", $this->amount);

正则表达式使用:

[   - Start of character class
 ^  - Negation
 \d - any digit
 .  - a literal perios
]   - end of character class

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...