PHP Regular Expression to remove all characters other than numbers and periods

I am trying to use preg_replaceto remove all characters from a string except numbers and period characters.

I can delete everything except numbers, however how can I make an exception for '.' period.

Can anyone help me out?

+5
source share
2 answers

Try the following:

$clean = preg_replace('/[^\\d.]+/', '', $str);

[^0-9.], . , . , ( ], \ ^ -).

+13

,

[^0-9.]

.

$output = preg_replace("/[^0-9.]/", "", $input);
+5

All Articles