Return to Snippet

Revision: 12115
at March 2, 2009 18:38 by gdvickery


Updated Code
$pageData = file_get_contents('http://geekforbrains.com');
if(preg_match_all('/<a\s+href=["\']([^"\']+)["\']/i', $pageData, $links, PREG_PATTERN_ORDER))
    return array_unique($links[1]);
return false;

Revision: 12114
at March 2, 2009 18:36 by gdvickery


Initial Code
$pageData = file_get_contents('http://geekforbrains.com');
if(preg_match_all('/<a\s+href=["\']([^"\']+)["\']/i', $pageData, $links, PREG_PATTERN_ORDER))
    return $links[1];
return false;

Initial URL


Initial Description
These 4 lines of code can be used to extract and return all links from any page using regex patterns. If links are found, an array is returned, else boolean false is returned.

Initial Title
Extract all links from a page using Regex

Initial Tags
regex, file, html, links

Initial Language
PHP