What are some common methods to extract a decimal number from a string in PHP?

When working with strings in PHP, it is common to encounter scenarios where you need to extract a decimal number from a string. One way to achieve this is by using regular expressions to match the decimal number pattern within the string. Regular expressions provide a flexible and powerful way to search for specific patterns in a string, making it ideal for extracting decimal numbers.

$string = "The price is $10.50";
$pattern = '/\d+\.\d+/';
preg_match($pattern, $string, $matches);
$decimal_number = $matches[0];

echo $decimal_number; // Output: 10.50