Are there any potential pitfalls to be aware of when using preg_replace to filter out non-numeric characters in PHP?
When using preg_replace to filter out non-numeric characters in PHP, one potential pitfall to be aware of is that it may inadvertently remove decimal points or negative signs from numbers. To avoid this issue, you can use a regular expression pattern that specifically allows for these characters to remain in the string while removing all other non-numeric characters.
// Input string
$input = "123abc-45.67";
// Remove all non-numeric characters except decimal points and negative signs
$output = preg_replace("/[^0-9\.\-]/", "", $input);
// Output: 123-45.67
echo $output;