Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get Feedburner feed and write its XML locally using PHP

Posted on 2012-03-17
5
Medium Priority
?
2,685 Views
Last Modified: 2013-11-18
I want to access the feed at

http://feeds.feedburner.com/BrownsvilleIndependentSchoolDistrict?format=xml

and write valid raw xml file locally with php

Thank you for any guidance you can offer ;-)
0
Comment
Question by:smetterd
5 Comments
 
LVL 10

Accepted Solution

by:
Pierre François earned 1000 total points
ID: 37734606
This PHP script gets the feed and saves it as raw html into the file local.xml in the current directory:

<?php
	$feed = file_get_contents ("http://feeds.feedburner.com/BrownsvilleIndependentSchoolDistrict?format=xml");
	if (!$feed) {
		echo "<p>Error: Couldn't open feed\n";
		exit;
	}
	file_put_contents ("local.xml", $feed);
?>

Open in new window

0
 
LVL 9

Expert Comment

by:rinfo
ID: 37734613
$url = "http://feeds.feedburner.com/BrownsvilleIndependentSchoolDistrict?format=xml"

    $str = file_get_contents($url);

    you can save/write string to a file

    $myfile = "NameOfTheFilewithPath";
    $fp = fopen($myfile, 'w');
    fwrite($fp, $str);
    fclose($fp);
   you can just download this file to your local system from web server.
    Please note that this will be a xml file.
0
 
LVL 9

Expert Comment

by:rinfo
ID: 37734620
This is an example how you can download the xml file using php
<?php

// define some variables
$local_file = 'rss.xml';
$server_file = 'Nameofthefilewithpath';//just put file name here and my earlier code like "rss.xml";

// set up basic connection
$conn_id = ftp_connect($ftp_server);//name of the server

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
    echo "Successfully written to $local_file\n";
} else {
    echo "There was a problem\n";
}

// close the connection
ftp_close($conn_id);

?>
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 total points
ID: 37734625
This appears to be an Atom feed.  Atom is similar to RSS; they are both specialized subsets of XML.  These are the easiest PHP functions you can use to copy a file from another server.
http://php.net/manual/en/function.file-get-contents.php
http://php.net/manual/en/function.file-put-contents.php

Take note of the setting of "allow URL fopen" - that affects the operation of the first.

You may find that file_get_contents() is not always your friend.  If the data source is unavailable, file_get_contents() will "hang" and your script will time out resulting in a fatal error.  If you find that this happens, you may want to change your script to use CURL, where you can control the amount of time devoted to acquiring the remote data, and handle timeout conditions gracefully.
0
 
LVL 2

Author Closing Comment

by:smetterd
ID: 37734766
Yes I had to switch to curl. Works great! Thanks to all!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question