Gotowy kod źródłowy z przykładem użycia:
Kod: Zaznacz cały
/*
* @Author: http://haker.edu.pl/
* @getLink($url) - Extract all links from URL
*/
function getLink($url) {
$soruce = file_get_contents($url);
$regEx = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
if (preg_match_all("/$regEx/siU", $soruce, $foundLinks, PREG_SET_ORDER)) {
$linki = array();
$tmp = array();
$sizeArray = sizeof($foundLinks);
for ($i = 0; $i < $sizeArray; $i++) {
$tmp[$i] = $foundLinks[$i][2];
}
$tmp = array_values(array_unique($tmp));
$links = array();
foreach ($tmp as $link) {
array_push($links, trim($link));
}
return $links;
}
}
//-------------------------------------
$links = getLink('http://wp.pl/');
foreach ($links as $link) {
echo $link . '<br>';
}