-
-
Save mach3/420b0f92c210fd77d0c8 to your computer and use it in GitHub Desktop.
WebページからフィードのURLを抽出する。(XPath版)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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