PHP 获取指定URl页面中所有链接

2019PHP高薪工程师学习路线图....>>>

    //获取指定URL页面中所有链接  
    function get_url_href($url){  
        $html = file_get_contents($url);  
        $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');  
            if(substr($url,0,4) == 'http') echo $url.'<br>';  
        }  
    }