How can preg_match_all be used to extract numbers between special characters in PHP strings?

To extract numbers between special characters in PHP strings using preg_match_all, you can define a regular expression pattern that matches the desired format and then use preg_match_all function to extract the numbers. The regular expression should include the special characters as delimiters and the \d+ pattern to match one or more digits. By using preg_match_all, you can capture all occurrences of the pattern in the input string.

$string = "The price is $50.99 and the discount is 20%.";
preg_match_all('/[\d\.]+/', $string, $matches);
print_r($matches[0]);