<?php



$the_url = isset($_REQUEST[&#39;url&#39;]) ? htmlspecialchars($_REQUEST[&#39;url&#39;]) : &#39;&#39;;
?>

<form method="post">
Please enter full URL of the page to parse (including http://):

<input type="text" name="url" size="65" value="<?php echo $the_url; ?>"/>

or enter text directly into textarea below:

<textarea name="text" cols="50" rows="15"></textarea>


<input type="submit" value="Parse Emails" />
</form>

<?php
if (isset($_REQUEST[&#39;url&#39;]) && !empty($_REQUEST[&#39;url&#39;])) {
// fetch data from specified url
$text = file_get_contents($_REQUEST[&#39;url&#39;]);
}
elseif (isset($_REQUEST[&#39;text&#39;]) && !empty($_REQUEST[&#39;text&#39;])) {
// get text from text area
$text = $_REQUEST[&#39;text&#39;];
}

// parse emails
if (!empty($text)) {
$res = preg_match_all(
"/[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}/i",
$text,
$matches
);

if ($res) {
foreach(array_unique($matches[0]) as $email) {
echo $email . "
";
}
}
else {
echo "No emails found.";
}
}

?>