Solved

Get Feedburner feed and write its XML locally using PHP

Posted on 2012-03-17
5
2,384 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:
pfrancois earned 250 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 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

685 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