Mastodon

multidisciplinary creative and full-stack developer

Menu
about
me
contact
links
journal
writings
social
posts
bookmarks
saves
news
breaking
projects
portfolio
uses
tools & stack
startyparty
homepage

PHP - Get All Links from a Website

December 19, 2018

Below is a quick little script for PHP that will grab all the links in a page and output them in a human-readable format. Nothing special, but useful.

$html = file_get_contents('http://www.example.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 />'; }
tags
PHPProgrammingTools
Contact & Social
© 2008 - 2026 Marko Bajlovic
Version5.11.3