Jump to content

quick simple retrive external xml (to cache on server)


Recommended Posts

I feel pretty stupid asking this but i need to retive xml data from an external source and include it into my cache script.

 

An easier way of putting it would be i need to display:

http://api.flickr.com/services/feeds/groups_discuss.gne?id=USERNO@DSD&lang=en-us&format=rss_200

as

http://www.myurl.com/flickerfeed.php

 

My minds just hitting a blank at the moment thanks in advance.

 

 

<?php
header("Content-Type: text/xml");
require_once '../includes/class_constants.php';
require_once '../includes/class_cache.php';
$cache = new cache(constants::CACHEDIR);
//start output buffer
ob_start();
//get cache data
$cache->get('flickr.txt', 86400);
//check the cache has loaded
if (!$cache->load())
{
	/* start content */
	//get file xml from here -> 'http://api.flickr.com/services/feeds/groups_discuss.gne?id=USERNO@DSD&lang=en-us&format=rss_200';
	/* end content */

	//load header into $header car
	$cache->newcache(ob_get_contents());
	//clean the output buffer
	ob_clean();
	//create the cache
	$cache->save('flickr.txt');
}
ob_end_clean();
echo $cache->export();
?>

Solved using:

 

<?php
header("Content-Type: text/xml");
require_once '../includes/class_constants.php';
require_once '../includes/class_cache.php';
$cache = new cache(constants::CACHEDIR);
//start output buffer
ob_start();
//get cache data
$cache->get('flickr.txt', 86400);
//check the cache has loaded
if (!$cache->load())
{
	/* start content */
	passthru("curl http://api.flickr.com/services/feeds/groups_pool.gne?id=USER@FSDF&lang=en-us&format=rss_200");
	/* end content */

	//load header into $header car
	$cache->newcache(ob_get_contents());
	//clean the output buffer
	ob_clean();
	//create the cache
	$cache->save('flickr.txt');
}
ob_end_clean();
echo $cache->export();
?>

You can simply use the file_get_contents() function to grab the feed and then add some parsing code to format it or use an existing class like http://www.phpclasses.org/browse/package/1820.html

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.