View Full Version : Getting the raw XML data from a RSS feed
nogenius
04-10-2008, 06:29 AM
Hi,
I am currently trying to parse Photobucket's RSS feed. Here's an example feed:
<removed>
When I try to use cURL to get the feed, I get a HTML version (the one that would be seen when the feed is accessed through a browser). I'd like to retrieve the raw XML (which I can see in a browser by right-clicking and selecting "View Source"), is there anyway I can do this through PHP/different parameters in cURL?
Inigoesdr
04-10-2008, 06:33 AM
Please be more careful when posting links. That particular one included a video with nudity, which is against the forum rules (http://www.codingforums.com/rules.htm).
nogenius
04-10-2008, 07:09 AM
Sorry about that, I'll be more careful next time.
Here's an example RSS feed (I checked thoroughly to make sure there was no offending material):
http://feed.photobucket.com/images/food/feed.rss
Have you tried fetching the feed using "file_get_contents" ?
mlseim
04-10-2008, 01:18 PM
I'm thinking that you might be wanting to do this .... but not sure ....
My test page: http://www.catpin.com/food.php
The PHP script:
<?php
# RSS FEED
$feed_url = "http://feed.photobucket.com/images/food/feed.rss";
# INITIATE CURL.
$curl = curl_init();
# CURL SETTINGS.
curl_setopt($curl, CURLOPT_URL,"$feed_url");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
# GRAB THE XML FILE.
$xmlTwitter = curl_exec($curl);
curl_close($curl);
# SET UP XML OBJECT.
# Use one or the other, depending on version of PHP
# and your webhost settings. Comment-out the one
# you are not using ...
//$xml = new SimpleXMLElement($xmlTwitter);
$xml = simplexml_load_string($xmlTwitter);
# HOW MANY ITEMS TO DISPLAY
$count = 5;
foreach ($xml->channel->item as $item) {
$newstring = $item->description;
if($count > 0){
echo"
<div style='font-family:arial; font-size:.8em;'>
<b>{$item->title}</b><br />
$newstring ... <a href='{$item->guid}'>read more</a>
<br /><br />
</div>
";
}
$count--;
}
?>
OR ... Do you mean this ...
Note, it actually is raw data, but HTML is processed when echoed to browser.
You could dump the data into a file instead.
Script example: http://www.catpin.com/food2.php
Here is the PHP script:
<?php
# RSS FEED
$feed_url = "http://feed.photobucket.com/images/food/feed.rss";
# INITIATE CURL.
$curl = curl_init();
# CURL SETTINGS.
curl_setopt($curl, CURLOPT_URL,"$feed_url");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
# GRAB THE XML FILE.
$data = curl_exec($curl);
echo"<pre>";
var_dump($data);
echo"</pre>";
curl_close($curl);
?>
nogenius
04-10-2008, 06:07 PM
Thanks mlseim, your var_dump code made me realize my mistake (I actually was erring in a later step, using XPath to try to pick out certain elements, and I assumed it was that I wasn't getting the raw XML because it was processed in my browser lilke you said). :)
mlseim
04-10-2008, 08:40 PM
nogenius ...
Also, see this: http://us3.php.net/curl
There are a gazillion examples (most over my head, but good anyhow).
Maybe there's a Curl method to dumping the results right into a file.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.