我正在使用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