-1

I have a list of urls that I want to extract the email or from the href or from the text. Each page has one email only.

The problem is that my list is big and can not do it manually.

<a href="mailto:EMAIL" class="spamspan">EMAIL</a>

How can I do this using PHP, regex?

EnexoOnoma
  • 8,454
  • 18
  • 94
  • 179

2 Answers2

2
/mailto:([a-zA-Z0-9_\.-]+@[\da-z\.-]+\.[a-z\.]{2,6})"/gm

see this demo https://regex101.com/r/mC7jM3/1

Vladu Ionut
  • 8,075
  • 1
  • 19
  • 30
  • Thank you but it seems that i can not get it from the actual page. I get this instead array(2) { [0]=> array(0) { } [1]=> array(0) { } } – EnexoOnoma Mar 16 '15 at 15:37
  • Actually I tried to get this `array(2) { [0]=> array(1) { [0]=> string(107) "name [at] domain [dot] com" } [1]=> array(1) { [0]=> string(54) "name [at] domain [dot] comr" } }` How can I output the `name [at] domain [dot] com` ? – EnexoOnoma Mar 16 '15 at 15:41
1
Extract  email from url contain 
<?php

  $the_url = isset($_REQUEST['url']) ? htmlspecialchars($_REQUEST['url']) : '';
  if (isset($_REQUEST['url']) && !empty($_REQUEST['url'])) {
      $text = file_get_contents($_REQUEST['url']);
  }
  elseif (isset($_REQUEST['text']) && !empty($_REQUEST['text'])) {
      $text = $_REQUEST['text'];
  }
  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 . "<br />";
    }
      }
      else {
          echo "No emails found.";
      }
  }

?>

<form method="post" action="">
    Please enter full URL of the page to parse (including http://):<br />
    <input type="text" name="url" size="65" value="<?php echo $the_url; ?>"/><br />
    <input type="submit" name="submit" value="Submit" />
</form>
debasish
  • 735
  • 1
  • 9
  • 14