Remove all non-numeric characters from a string; [^0-9] doesn't match as expected

You can use the preg_replace function in PHP to remove all non-numeric characters from a string. The regular expression to match non-numeric characters is /[^0-9]/, and you can use an empty string as the replacement.

Here is an example:

<?php

$string = "Hello 123 World 456";
$string = preg_replace('/[^0-9]/', '', $string);
echo $string; // Output: "123456"

In this example, the preg_replace function removes all characters that are not 0-9 and replaces them with an empty string. The resulting string will contain only numeric characters.

If you want to remove all non-numeric characters except '.' and ',' use the following pattern

<?php

$string = "Hello 123, World 456.";
echo $string = preg_replace('/[^0-9,.]/', '', $string);

Also make sure you have enabled PCRE library in your server.