What are some common methods for extracting email addresses from text in PHP?

Extracting email addresses from text in PHP can be achieved using regular expressions. One common method is to use the preg_match_all function with a regular expression pattern that matches email addresses. This function will return an array of all email addresses found in the text.

$text = "Contact us at email@example.com or support@example.com for assistance.";

preg_match_all('/[\w\.-]+@[\w\.-]+/', $text, $matches);

$emails = $matches[0];

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