Email Extractor


/ Published in: PHP
Save to your folder(s)

Extract email addresses from submitted text or a full URL


Copy this code and paste it in your HTML
  1. <?php
  2. $the_url = isset($_REQUEST['url']) ? htmlspecialchars($_REQUEST['url']) : '';
  3. ?>
  4.  
  5. <form method="post">
  6. Please enter full URL of the page to parse (including http://):<br />
  7. <input type="text" name="url" size="65" value="<?php echo $the_url; ?>"/><br />
  8. or enter text directly into textarea below:<br />
  9. <textarea name="text" cols="50" rows="15"></textarea>
  10. <br />
  11. <input type="submit" value="Parse Emails" />
  12. </form>
  13.  
  14. <?php
  15. if (isset($_REQUEST['url']) && !empty($_REQUEST['url'])) {
  16. // fetch data from specified url
  17. $text = file_get_contents($_REQUEST['url']);
  18. }
  19. elseif (isset($_REQUEST['text']) && !empty($_REQUEST['text'])) {
  20. // get text from text area
  21. $text = $_REQUEST['text'];
  22. }
  23.  
  24. // parse emails
  25. if (!empty($text)) {
  26. "/[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}/i",
  27. $text,
  28. $matches
  29. );
  30.  
  31. if ($res) {
  32. foreach(array_unique($matches[0]) as $email) {
  33. echo $email . "<br />";
  34. }
  35. }
  36. else {
  37. echo "No emails found.";
  38. }
  39. }
  40.  
  41. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.