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


if have following values:

 $var1 = ar3,373.31   $var2 = 12.322,11t 

how can create new variable , set copy of data has non-numeric characters removed, exception of commas , periods? values above return following results:

 $var1_copy = 3,373.31   $var2_copy = 12.322,11 

you use preg_replace swap out non numeric characters , comma , period/full stop follows:

<?php     $teststring = "12.322,11t";     echo preg_replace("/[^0-9,.]/", "", $teststring); ?> 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -