从网址列表中提取电子邮件

时间:2015-03-16 15:05:02

标签: php regex

我有一个我想要提取电子邮件或来自href或文本的网址列表。每个页面只有一封电子邮件。

问题是我的列表很大,无法手动执行。

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

我怎样才能使用PHP,正则表达式?

2 个答案:

答案 0 :(得分:2)

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

请参阅此演示https://regex101.com/r/mC7jM3/1

答案 1 :(得分:0)

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>
相关问题