删除重复链接

bru*_*ine 2 php web-crawler

我想抓取pdf链接.但是我得到的一些链接是双倍的.如何删除其中一个双链接?谢谢 :)

<?php
<include 'simple_html_dom.php';
$url = 'http://scholar.google.com/scholar?hl=en&q=data+mining&btnG=&as_sdt=1%2C5&as_sdtp=';
$html = file_get_html($url) or die ('invalid url');
foreach($html->find('a') as $e) {
    $link= $e->href;
    if (preg_match('/\.pdf$/i', $link)) {
       print_r($link);
    }
}
?>
Run Code Online (Sandbox Code Playgroud)

Gal*_*len 5

将链接放在一个数组中,然后使用array_unique()

foreach($html->find('a') as $e) {
    $link= $e->href;
    if (preg_match('/\.pdf$/i', $link)) {
       $links[] = $link;
    }
}
$links = array_unique( $links );
Run Code Online (Sandbox Code Playgroud)