What are some common methods for extracting emails from a text file using PHP?

Extracting emails from a text file using PHP involves reading the content of the file, identifying email patterns, and extracting them using regular expressions. One common method is to use the `preg_match_all` function with a regular expression pattern that matches email addresses.

$file_content = file_get_contents('emails.txt');
$pattern = '/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/';
preg_match_all($pattern, $file_content, $matches);

$emails = $matches[0];

foreach ($emails as $email) {
    echo $email . "\n";
}