Remove non-numeric characters (except periods and commas) from a string

前端 未结 5 1928
一整个雨季
一整个雨季 2020-11-30 23:57

If I have the following values:

 $var1 = AR3,373.31

 $var2 = 12.322,11T

How can I create a new variable and set it to a copy of the data t

5条回答
  •  一向
    一向 (楼主)
    2020-12-01 00:23

    Simplest way to truly remove all non-numeric characters:

    echo preg_replace('/\D/', '', $string);
    

    \D represents "any character that is not a decimal digit"

    http://php.net/manual/en/regexp.reference.escape.php

提交回复
热议问题