Skip to content

Instantly share code, notes, and snippets.

@mach3 mach3/getfeedurl.php Secret
Created Jan 31, 2011

Embed
What would you like to do?
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
You can’t perform that action at this time.