Solved

Get Feedburner feed and write its XML locally using PHP

Posted on 2012-03-17
5
2,522 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article discusses four methods for overlaying images in a container on a web page
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)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

623 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