code in php for rss feed from any news site
Moderator: General Moderators
code in php for rss feed from any news site
Can any one tell me the code in php for rss feed from any news site .....
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: code in php for rss feed from any news site
It is just an XML document. Use cURL, fsocketopen, the stream functions or other library to access the URL. Then parse the XML. It is in a standard format.
(#10850)
Re: code in php for rss feed from any news site
Pretty much what was said there. I'd go a step further, and parse it with PHP functions. Since RSS is basically XML, you can use simplexml_load_string to load XML and easily parse it.Christopher wrote:It is just an XML document. Use cURL, fsocketopen, the stream functions or other library to access the URL. Then parse the XML. It is in a standard format.
Here's an example:
Code: Select all
<?php
$content = file_get_contents("https://twitrss.me/twitter_user_to_rss/?user=pazuzu156");
$xml = simplexml_load_string($content);
$channel = $xml->channel;
$items = $channel->item;
$string = "<pre>RSS Feed\n\n";
foreach($items as $item)
{
$string .= "Item\n====\n";
$string .= "Title: {$item->title}\n";
$string .= "Description: {$item->description}\n";
$string .= "Published Date: {$item->pubDate}\n";
$string .= "GUID: {$item->guid}\n";
$string .= "Link: {$item->link}\n\n";
}
echo $string . "</pre>";
- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156