0

我需要从下面的 html 代码中检索电子邮件数据

<a href="mailto:contact@rovio.com" rel="nofollow">Email Developer</a>

我已使用此代码获取电子邮件地址,但未能获取。

preg_match('@^(?:mailto:)?([^/]+)@i', $data, $matches);
$email = $matches[1];
echo $email;

你能看出什么问题吗?

4

1 回答 1

0

What you just can do is

  • just strip mailto: from the href attribute
  • then filter the mail adress

$string = '<a href="mailto:contact@rovio.com" rel="nofollow">Email Developer</a>';
$parsing = new SimpleXmlElement($string);
$attrs = (array)$parsing->attributes();
$mail = str_replace('mailto:','',$attrs['href']);
if(filter_var($mail,FILTER_VALIATE_MAIL)){//if it is a good email
   //goooo
}
于 2012-12-19T12:31:45.230 回答