Solved

Get Feedburner feed and write its XML locally using PHP

Posted on 2012-03-17
5
2,171 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
Comment Utility
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
Comment Utility
$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
Comment Utility
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 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
Comment Utility
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
Comment Utility
Yes I had to switch to curl. Works great! Thanks to all!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now