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
Post a Comment