2010-08-12 6 views
0

fff.html은 일부에있는 이메일 주소와 이메일이 HREF 흔한 링크가 일부는, 내가스크랩 이메일 주소

[email protected],[email protected],[email protected] 

가 나는이 다음과 같은 형식으로 그들과 출력을들을 긁어하지 않을 것입니다 href가 연결되어 있지만 뭔가하는 사람을 얻을 수있는 간단한 스크레이퍼 내가가 lorem ipsum의 원래 사용을 위해 추가 포인트를 획득해야

<?php 
    $url = "fff.html"; 
    $raw = file_get_contents($url); 

    $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B"); 
    $content = str_replace($newlines, "", html_entity_decode($raw)); 

    $start = strpos($content,'<a href="mailto:'); 
    $end = strpos($content,'"',$start) + 8; 
    $mail = substr($content,$start,$end-$start); 

    print "$mail<br />"; 
    ?> 

이상한입니다

답변

3

문제는 당신이 m이 있다면 무엇인가 HTML 페이지의 한 전자 메일 주소보다 substr은 첫 번째 인스턴스 만 반환합니다. 다음은 모든 이메일 주소를 구문 분석하는 스크립트입니다. 당신은 그것을 사용하기 위해 약간 조정할 필요가 있습니다. 요청한 CSV 형식으로 결과가 출력됩니다.

<?php 
$url = "fff.html"; 
$raw = file_get_contents($url); 

$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B"); 
$content = str_replace($newlines, "", html_entity_decode($raw)); 

$start = strpos($content, '<body>'); 
$end = strpos($content, '</body>'); 
$data = substr($content, $start, $end-$start); 

$pattern = '#a[^>]+href="mailto:([^"]+)"[^>]*?>#is'; 
preg_match_all($pattern, $data, $matches); 

foreach ($matches[1] as $key => $email) { 
    $emails[] = $email; 
} 
echo implode(', ', $emails); 
?>