Show Netflix Movies using PHP 5
Posted on August 30, 2005 at 12:02 PM EST
I wrote the following PHP script for use on the Netflix page that I recently added to my site. The script parses the RSS feeds that are available for my Movie Queue and Previously Viewed Movies using the URLs that Netflix provides for my account. It uses PHP 5’s new SimpleXML extension which really simplifies parsing XML documents by quickly extracting data. In order to accomplish the same results under PHP 4 a lot of code would have been needed.
<?php
// define feed urls
$queue_feed = 'http://rss.netflix.com/QueueRSS?id=ENTER-YOUR-ID-HERE'; // url to queue feed
$recent_activity_feed = 'http://rss.netflix.com/TrackingRSS?id=ENTER-YOUR-ID-HERE'; // url to the most recent rental activity feed
// function that parses the xml and converts it to a nice ordered list
function show_movies($file) {
$xml = simplexml_load_file($file);
echo "<ol>\n";
foreach ($xml->channel->item as $item) {
$link = $item->link;
$title = $item->title;
$title = preg_replace("[[0-9]+- |Shipped: |Received: ]", '', $title);
echo " <li><a href=\"$link\">$title</a></li>\n";
}
echo "</ol>\n\n";
}
echo "<h2>Movie Queue</h2>\n";
show_movies($queue_feed);
echo "<h2>Previously Viewed Movies</h2>\n";
show_movies($recent_activity_feed);
?>
In order to use the script your server will need to be running PHP 5. Just replace “ENTER-YOUR-ID-HERE” with your id number and you’re ready to go. You can get the id by logging into your Netflix account then clicking on the RSS link at the bottom of the page. The number can be found under the Personalized Feeds section and it starts after the = sign in the URL.
There is 1 comment on this post. Post yours →
Tagged with netflix, php, scripts, webdev

1
Posted by web host on April 07, 2010 EST
Thanks for sharing this post. This is a very helpful and informative material. Good post and keep it up.