Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Find All Links on a Page
$html = file_get_contents('');
$dom = new DOMDocument();
// 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