Created
March 10, 2021 09:49
-
-
Save dev-w3/de3e77354d8c3c60beb8bcf4ad0085cc to your computer and use it in GitHub Desktop.
Get All href link from third party URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = "http://stackoverflow.com/"; | |
$ch = curl_init(); | |
$timeout = 5; | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); | |
$html = curl_exec($ch); | |
curl_close($ch); | |
# Create a DOM parser object | |
$dom = new DOMDocument(); | |
# loadHTML might throw because of invalid HTML in the page. | |
@$dom->loadHTML($html); | |
# Iterate over all the <a> tags | |
foreach($dom->getElementsByTagName('a') as $link) { | |
# Show the <a href> | |
echo "https://www.stackoverflow.com".$link->getAttribute('href'); | |
echo "<br />"; | |
// echo $link->nodeValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To Get All href link from third party URL