What are the limitations and challenges of using PHP to scrape data from web pages, such as extracting email addresses from HTML source code?
One limitation of using PHP to scrape data from web pages, such as extracting email addresses from HTML source code, is that it can be difficult to accurately extract email addresses due to the varying formats they can appear in. To address this challenge, you can use regular expressions to search for patterns that resemble email addresses in the HTML source code.
$html = file_get_contents('https://example.com');
preg_match_all('/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/', $html, $matches);
$emailAddresses = $matches[0];
foreach ($emailAddresses as $email) {
echo $email . "<br>";
}