0

I have write some code using simple html dom to create sitemap creator website. But it gives me duplicate links. Here is my code.

<?php 
require_once('simple_html_dom.php');
$bb= new simple_html_dom();
$b="http://mysite.co/";
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $b);
curl_setopt($curl, CURLOPT_REFERER, $b);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$str = curl_exec($curl);
curl_close($curl);
$bb->load($str);
$link=$bb->find("a");
foreach($link as $a){
echo $a."<br />";
}
?>

I want to get only one specific link not duplicate. Thanks in Advance

PseudoAj
  • 5,234
  • 2
  • 17
  • 37

1 Answers1

0

Try this

$links_array = array();
foreach($link as $a){
    if(!in_array(trim($a),$links_array))
        $links_array[] = $a;
}
Asim
  • 56
  • 5