How to find all the links on a web page in PHP

1 Answer

0 votes
    $html = file_get_contents('http: //www.avibootz.com');
     
    $dom = new DOMDocument();
    @$dom->loadHTML($html);
     
    $xpath = new DOMXPath($dom);
    $hrefs = $xpath->evaluate("/html/body//a");
     
    for ($i = 0; $i < $hrefs->length; $i++) 
    {
        $href = $hrefs->item($i);
        $url = $href->getAttribute('href');
        echo $url.'<br />';
    }

/*
 
run:
 
http: //cprogramming.bootzlabs.com/get-c-compiler/
http: //collectivesolver.com/
http: //webshopy.com/
http: //www.coupondiscountblog.com/
http: //www.buyfrompictures.com/
http: //www.seek4info.com/
http: //www.occupationstools.com/
http: //www.bootzstore.com/
http: //www.allwebhostingsites.com/
http: //www.allonpage.com/
http: //www.readersbuyers.com/
http: //www.digitalproductsdeals.com/
http: //www.madalpha.com/
http: //www.bootznotes.com
http: //www.knowrex.com
 
*/

?>


answered Mar 1, 2015 by avibootz
edited Mar 1, 2015 by avibootz

Related questions

...