В том примере кода это есть:
// не парсим протоколы if (preg_match("#^(mailto|skype|magnet|ftp):#i", $href)) continue;
$host = "www.test.ru"; $links = array(); $content = preg_replace(array("#<!--[\s\S]+?-->#", "#<script[\s\S]+?</script>#i"), "", file_get_contents("http://www.test.ru")); if (preg_match_all("@<a\s([^>]*)?href\s*=\s*[\"']?([^#>'\"\s]*)[\"']?([^>]*)?>@i", $content, $matches)) { // убираем www if (strpos($host, "www.") === 0) $host = substr($host, 4); foreach ($matches[2] as $n => $href) { // атрибуты тега, если надо парсить $attr = $matches[1][$n]." ".$matches[3][$n]; if (empty($href)) continue; // не парсим протоколы if (preg_match("#^(mailto|skype|magnet|ftp):#i", $href)) continue; // абсолютная ссылки if (preg_match("#^(https?:)?//(www\.)?([^/]+)(/.*)?$#", $href, $match)) { if (strcmp($host, strtolower($match[3])) !== 0) continue; $href = $match[4]; } // если относительная не начинается с "/" if (strpos($href, "/") !== 0) $href = "/".$href; //$links[] = $href." | ".$matches[0][$n]; $links[] = "http://".$host.$href; } } print_r($links);
Спасибо вам за помощь! Вроде всё работает, я конечно его доработал немного чтобы дублей не было и чтобы не собирал ссылки типа javascript:, #