To give an idea how you can POST a url for some RSSFeed
to a script and then process it perhaps this might help.
To process the contents of an RSSFeed typically one would use DOMDocument
or SimpleXML
- the code here simply loads the remote XML file directly into the DOMDocument
and instantiates an XPath object to further query to find nodes. There are many other ways one could do this - but it was quickly written just as example.
<html>
<head>
<title>RSS</title>
</head>
<body>
<form method='post'>
<input type='text' name='name' value='https://www.huffingtonpost.co.uk/feeds/index.xml' />
<input type='submit'>
</form>
<?php
if( $_SERVER['REQUEST_METHOD']=='POST' && !empty( $_POST['name'] ) ){
$dom=new DOMDocument;
$dom->load( $_POST['name'] );
$xp=new DOMXPath( $dom );
$col=$xp->query( '//channel/item' );
if( $col->length > 0 ){
foreach( $col as $node ){
printf(
'<h3>%s</h3>',
$xp->query('title',$node)->item(0)->textContent
);
}
}
}
?>
</body>
</html>
a snippet from the output:
<h3>Where To Travel In 2020: The Top 10 Emerging Destinations</h3>
<h3>Gavin And Stacey Christmas Special: First Reviews Of Reunion Episode Are In</h3>
<h3>Jeremy Corbyn Speaks To The Common People | The People's Election</h3>
A more complete example showing multiple possible RSS feeds and more fields from each article:
<html>
<head>
<title>RSS</title>
</head>
<body>
<form method='post'>
<select name='name'>
<optgroup label='World news'>
<option>http://rssfeeds.usatoday.com/UsatodaycomGolf-TopStories
<option>http://feeds.reuters.com/Reuters/worldNews
<option>http://rss.cnn.com/rss/edition_world.rss
</optgroup>
<optgroup label='UK news'>
<option>http://feeds.bbci.co.uk/news/rss.xml
<option>http://feeds.skynews.com/feeds/rss/uk.xml
<option>http://feeds.reuters.com/reuters/UKdomesticNews
</optgroup>
<optgroup label='US news'>
<option>http://rssfeeds.usatoday.com/usatoday-newstopstories
<option>http://feeds.reuters.com/Reuters/domesticNews
<option>http://feeds.skynews.com/feeds/rss/us.xml
</optgroup>
<optgroup label='Miscellaneous'>
<option>https://www.wired.com/feed
<option>http://rss.slashdot.org/Slashdot/slashdot
<option>https://www.huffingtonpost.co.uk/feeds/index.xml
</optgroup>
</select>
<input type='submit'>
</form>
<?php
if( $_SERVER['REQUEST_METHOD']=='POST' && !empty( $_POST['name'] ) ){
$url=$_POST['name'];
$max=150;
$ellipsis=str_repeat('.',5);
$dom=new DOMDocument;
$dom->load( $url );
$xp=new DOMXPath( $dom );
$col=$xp->query( '//channel/item' );
if( $col->length > 0 ){
echo '<ul>';
foreach( $col as $node ){
try{
$description=$xp->evaluate('string(description)',$node);
if( strlen( $description ) > $max )$description=substr( $description, 0, $max ) . $ellipsis;
$category=$xp->evaluate( 'string(category)', $node );
printf(
'<li>
<a href="%s" target="_blank">%s</a>
<div>Category: %s</div>
<p>%s</p>
</li>',
$xp->evaluate( 'string(link)', $node ),
$xp->evaluate( 'string(title)',$node ),
$category,
$description
);
}catch( Exception $e ){
continue;
}
}
echo '</ul>';
} else {
echo 'nothing found for given XPath query';
}
}
?>
</body>
</html>