What are the potential pitfalls of using substr() versus preg_match() for string manipulation in PHP?

Using substr() for string manipulation in PHP can be limiting as it only allows for fixed-length extractions, while preg_match() provides more flexibility with regular expressions. One potential pitfall of substr() is that it may not be suitable for extracting dynamic patterns within a string. To overcome this limitation, it is recommended to use preg_match() when dealing with more complex string manipulation tasks.

$string = "Hello, World!";
$pattern = "/Hello, (.*?)!/"; // Regular expression pattern to extract text between "Hello, " and "!"
preg_match($pattern, $string, $matches);
echo $matches[1]; // Output: World