kode yard
all about C++ and PHP
Tuesday, October 27, 2009
feed finder in php
Here is a php snippet which finds the rss and atom links of a web site by parsing the meta information in the header section of the page.
<br /><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br /><html xmlns="http://www.w3.org/1999/xhtml"> <br /><head> <br /><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <br /><title>Feed finder</title> <br /></head> <br /> <br /><body> <br /><?php <br />if(isset($_POST['link']) && (strlen($_POST['link'])>0)) { <br /> include_once('simple_html_dom.php'); <br /> $html = file_get_html(trim($_POST['link'])); <br /> $feed_type = array('application/rss+xml', <br /> 'text/xml', <br /> 'application/atom+xml', <br /> 'application/x.atom+xml', <br /> 'application/x-atom+xml'); <br /> foreach($html->find('link') as $element) { <br /> foreach($feed_type as $rs) { <br /> if(strtolower($element->type) == $rs) { <br /> echo "<h3>" . $element->title . "</h3>\n"; <br /> echo "<h3>" . $element->href . "</h3>\n"; <br /> echo "<h3>" . $element->type . "</h3>\n"; <br /> echo "<h3>---------------------</h3>\n"; <br /> } <br /> } <br /> } <br />} <br />else <br />{ <br />?> <br /><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <br /><table align="center" width="50%"> <br /><tr> <br /><td align="right">Link : </td> <br /><td align="left"><input type="text" name="link" /></td> <br /></tr> <br /><tr> <br /><td align="right"><input type="submit" name="submit" value="Submit" /></td> <br /><td align="left"><input type="reset" name="reset" value="clear" /></td> <br /></tr> <br /></table> <br /></form> <br /><?php <br />} <br />?> <br /></body> <br /></html> <br />
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment