PHP - Get Links From URL
From Global Programming Syntax
When creating a website or even a bot to scan the website, you may face a situation where you need to get all the links from a webpage well this function does just that. The function shown below will grab the info after any src= and href= tags and place them into an array. The array is then returned by the function. If your interested then try the script below:
function getlinks($url) {
$data=file_get_contents($url);
preg_match_all('/(href|src)\=(\"|\')[^\"\'\>]+/i',$data,$media);
unset($data);
$data=preg_replace('/(href|src)(\"|\'|\=\"|\=\')(.*)/i',"$3",$media[0]);
return $data;
}
Then to use it:
foreach (getlinks('http://www.google.com.au/') AS $link) {
echo $link.'<br>';
}
