Remove non-numeric characters (excluding periods and commas) from a string (i.e. remove all characters except numbers, commas, and periods)

You could use preg_replace to swap out all non-numeric characters and the comma and period/full stop as follows:

$testString = '12.322,11T';
echo preg_replace('/[^0-9,.]+/', '', $testString);

The pattern can also be expressed as /[^\d,.]+/

Leave a Comment