Solved

Get Feedburner feed and write its XML locally using PHP

Posted on 2012-03-17
5
2,339 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 109

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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:

861 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