What are the advantages of using preg_match_all over preg_match in PHP?
When dealing with multiple occurrences of a pattern within a string, using preg_match_all in PHP is more efficient and convenient than using preg_match. preg_match_all returns all matches in the string, while preg_match only returns the first match found. This can be especially useful when you need to extract multiple pieces of information from a string at once.
<?php
$string = "Hello, my name is John and I am 25 years old. I live in New York.";
$pattern = '/\b[a-zA-Z]+\b/';
preg_match_all($pattern, $string, $matches);
print_r($matches[0]);
?>