Php抓取电子邮件模式
可能重复:Php抓取电子邮件模式,php,regex,Php,Regex,可能重复: 我想通过下面的纸条获取带有页面的电子邮件,但我不确定preg_match_all中使用的模式 $original_file = file_get_contents("http://www.example.com/"); $stripped_file = strip_tags($original_file, "<a>"); preg_match_all("/<a(?:[^>]*)href=\"([^\"]*)\"(?:[^>]*)>(?:[^
我想通过下面的纸条获取带有页面的电子邮件,但我不确定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
$original\u file=文件获取内容(“http://www.example.com/");
$stripped_file=strip_标签($original_file,“”);
preg\u match\u all(“/]*)href=\”([^\“]*)\”(?:[^>]*)>(?:[^编辑:我刚意识到你的意思是邮件链接
请回答:
使用HTML解析器可能会更幸运,例如,它可以让您以更自然的方式解析HTML文档,例如:
// Find all anchors, returns a array of element objects
$ret = $html->find('a');
然后循环遍历返回元素的数组,并检查href
中是否有类似@symbol的内容。strip_tags()的第二个参数设置要保留的标记。