How can PHP developers efficiently extract only the numerical value from a string that may contain additional characters or symbols?

When extracting only the numerical value from a string that may contain additional characters or symbols, PHP developers can use regular expressions to filter out non-numeric characters. By using the preg_replace function with a regular expression pattern that matches any character that is not a digit, developers can efficiently extract the numerical value from the string.

$string = "abc123def456ghi";
$numeric_value = preg_replace("/[^0-9]/", "", $string);
echo $numeric_value; // Output: 123456