Skip to content

Instantly share code, notes, and snippets.

@Shaz3e
Created July 4, 2015 22:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Shaz3e/07dc7a8dee0747af0db1 to your computer and use it in GitHub Desktop.
Find All Links on a Page
$html = file_get_contents('http://www.example.com');
$dom = new DOMDocument();
@$dom->loadHTML($html);
// grab all the on the page
$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 />';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment