Skip to content

Instantly share code, notes, and snippets.

@JunaidQadirB
Created July 25, 2011 19:00
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 JunaidQadirB/1104883 to your computer and use it in GitHub Desktop.
Save JunaidQadirB/1104883 to your computer and use it in GitHub Desktop.
Checks whether a web site has feeds if so, grabs its url returns false otherwise
/**
* Checks whether a web site has feeds
* if so, grabs its url returns false otherwise
* @author Junaid Qadir baloch
* @version 0.1 11:12 PM 7/25/2011
* @param sting $url
* @return boolean
*/
function getFeedUrls($url)
{
$domDoc = new DOMDocument ( "1.0", "UTF-8" );
$nodeList = new DOMNodeList ();
/**
* @$domDoc->loadHTMLFile ( $url ))
* (@) is used to suppress the errors
* that may occur due to invalid html on the page
*/
if (@$domDoc->loadHTMLFile ( $url ))
{
$content = $domDoc->saveHTMLFile ( "cache.html" );
$expression = '//link [@rel="alternate"]'; // [@rel=\"alternate\"]";
$domXPath = new DOMXPath ( $domDoc );
$elements = $domXPath->query ( $expression );
$feedUrls = array ();
foreach ( $elements as $element )
{
if ($element->hasAttributes ())
{
foreach ( $element->attributes as $attribute )
{
if ($attribute->nodeName == "href")
{
$feedUrls [] = $attribute->nodeValue;
}
}
}
}
} else
{
return FALSE;
}
return $feedUrls;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment