PHP script to extract emails

This is a simple php script to extract email address from webpage. This will extract all unique emails and output each in new line. You can modify this script as per your need.

<?
$url="http://example.com/";
$text=file_get_contents($url);
$res = preg_match_all(
"/[a-z0-9]+[_a-z0-9.-]*[a-z0-9]+@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})/i",
$text,
$matches
);
if ($res) {
foreach(array_unique($matches[0]) as $email) {
echo $email . "<br />";
}
}
else {
echo "No emails found.";
}
?>

Liked It? Get Free updates in your Email

Delivered by feedburner

Leave a Reply

Your email address will not be published. Required fields are marked *