Longhorn PHP 2025 - Speakers and Schedule Announced!

Voting

: zero minus zero?
(Example: nine)

The Note You're Voting On

danny dot nunez15 at gmail dot com
11 years ago
A simple function to grab all links in a page.

function get_links($url) {

// Create a new DOM Document to hold our webpage structure
$xml = new DOMDocument();

// Load the url's contents into the DOM

$xml->loadHTMLFile($url);

// Empty array to hold all links to return
$links = array();

//Loop through each <a> tag in the dom and add it to the link array
foreach ($xml->getElementsByTagName('a') as $link) {
$url = $link->getAttribute('href');
if (!empty($url)) {
$links[] = $link->getAttribute('href');
}
}

//Return the links
return $links;
}

<< Back to user notes page

To Top