private static function extractLinks($sourceUrl, $html) { $links = array(); if (preg_match_all("/<link(?:\\s+\\w+=[\"'][^\"']*[\"'])+\\s*\\/?>/", $html, $matches)) { foreach ($matches[0] as $match) { if (preg_match_all("/(\\w+)=[\"']([^\"']*)[\"']/", $match, $submatches, PREG_SET_ORDER)) { $attrs = array(); foreach ($submatches as $submatch) { list(, $key, $value) = $submatch; $attrs[strtolower($key)] = $value; } if (strcasecmp($attrs["rel"], "alternate") === 0 && (strcasecmp($attrs["type"], "application/rss+xml") === 0 || strcasecmp($attrs["type"], "application/atom+xml") === 0)) { $link = new stdClass(); $link->title = $attrs["title"]; $link->url = FeedParser::resolveUrl($sourceUrl, $attrs["href"]); $links[] = $link; } } } } return $links; }