可能的重复项:
用于提取邮件收件人:地址的正则表达式
我想通过以下 scrip 获取页面中的电子邮件,但我不确定在 preg_match_all 中使用的模式。
$original_file = file_get_contents("http://www.example.com/");
$stripped_file = strip_tags($original_file, "<a>");
preg_match_all("/<a(?:[^>]*)href='"([^'"]*)'"(?:[^>]*)>(?:[^<]*)<'/a>/is", $stripped_file, $matches);
header("Content-type: text/plain");
print_r($matches); //View the array to see if it worked
使用HTML解析器(如PHP Simple HTML Dom Parser(可能会有更多的运气,它可以让你以更自然的方式解析HTML文档,例如:
// Find all anchors, returns a array of element objects
$ret = $html->find('a');
然后遍历返回元素的数组,并检查href
中是否有类似 @ 符号的内容。
编辑:我刚刚意识到你的意思是邮件:链接
在这里回答:
用于提取邮件收件人:地址的正则表达式