What is the purpose and syntax of the preg_match_all function in PHP?
The preg_match_all function in PHP is used to perform a global regular expression match on a string and return all matches. This function allows you to extract multiple occurrences of a pattern from a string. The syntax for preg_match_all is preg_match_all($pattern, $subject, $matches), where $pattern is the regular expression pattern to search for, $subject is the string to search within, and $matches is an array that will be filled with the matched patterns.
$string = "The quick brown fox jumps over the lazy dog";
$pattern = '/\b\w{4}\b/';
preg_match_all($pattern, $string, $matches);
print_r($matches[0]);
Keywords
Related Questions
- Are there specific coding conventions or standards that should be adhered to when working with external APIs in PHP?
- What role does the PHP configuration setting register_globals play in this PHP forum thread?
- Are there any recommended PHP libraries or classes specifically designed for parsing PDF files?