What is the function preg_match_all() used for in PHP?
The function preg_match_all() in PHP is used to perform a global regular expression match on a string and return all matches. This function is particularly useful when you need to extract multiple occurrences of a pattern from a string.
<?php
$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]);
?>
Related Questions
- How can access denied errors for LOAD DATA INFILE be resolved when importing data into a MySQL database using PHP scripts?
- How can developers effectively troubleshoot and address errors related to interface implementation in PHP plugins or classes?
- What potential issue is the user facing with the database query in the provided PHP code?