Skip to content

Instantly share code, notes, and snippets.

@mach3
Created January 31, 2011 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mach3/420b0f92c210fd77d0c8 to your computer and use it in GitHub Desktop.
Save mach3/420b0f92c210fd77d0c8 to your computer and use it in GitHub Desktop.
WebページからフィードのURLを抽出する。(XPath版)
<?php
function getFeedUrl( $url ){
$doc = DOMDocument::loadHTMLFile( $url );
$xpath = new DOMXpath( $doc );
$q = '/html/head/link[contains(@rel, "alternate")]'
. '[@type="application/x.atom+xml" or @type="application/atom+xml" or '
. '@type="application/xml" or @type="text/xml" or @type="application/rss+xml" or '
. '@type="application/rdf+xml"]';
$eles = $xpath->query( $q );
if( !$eles->length ) return false;
return $eles->item(0)->getAttribute("href");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment