Alexander Jones Alexander Jones - 1 year ago 56
HTML Question

array_unique() in php simple html dom

I wrote the code blow to get all unique links from a url:

include_once ('simple_html_dom.php');

$html = file_get_html('');

foreach($html->find('a') as $element){
$input = array($element->href = $element->href . '<br />');

but I really can't understand why it shows the duplicated links too!
is there any problem with the function
simple html dom
and there's another thing I guess is related to the problem: when you execute this you see all of the link that it extracted are in one key I mean this :

array(key => all values)

Is there any one who can solve this?

Answer Source

I believe you want it more like this:

$temp = array();
foreach($html->find('a') as $element) { 
    $temp[] = $element->href;

echo '<pre>' . print_r(array_unique($temp), true) . '</pre>';