I'm currently available for freelance projects. Enquire within.

feedburner

I recently decided to see how easy it would be to pull out my feedburner stats and display them on a web page. After a bit of research I found the most common way to achieve this was with feedburners built in feedcount option(found in under the publicise tab). This works by taking your feed count and wrapping it into a branded box. Although there is nothing wrong with this, I wanted to give my feed a bit more customizability. So I created a custom PHP function to pull out any one of your feeds attributes, this post will show you how.

download1111

demo11

Make Your Feed Public

The first step in displaying your feedburner count is to make your feed public. This can be achieved by going to http://feedburner.google.com/fb/a/myfeeds when logged in select your feed and choose the publicize tab, then select feedcount on the sub menu, this should give you the options to set your service as active. Your feed will now be accessible in an XML format.

The Function

feedburner_stats() uses PHP5′s simplexml_load_file to pull out the XML of your feed. feedburner_stats() requires 2 parameters in order to work. The first $feed, this relates to the URI of your feed address. To find this select edit feed details, you should see it in the feed address. You only need the address after http://feeds.feedburner.com/[HERE]

The second argument is the $attribute. Here you have the selection of 4 possible attributes of the feed:

  • date
  • circulation
  • hits
  • reach

Depending on which element you wish to display simply add the word in the second argument. The function itself looks like this:

<?php
function feedburner_stats($feed, $attribute) {
 if ( !$feed ) { echo('[No Feed]'); } //user must pass in their URI
 if ( !$attribute ) { echo('[No Attribute]'); }//user must pass in their attribute
 $xmlobj = simplexml_load_file("http://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=".$feed);
 echo($xmlobj->feed->entry->attributes()->$attribute);
 }
?>

Calling The Function

In order to use the function simply call it where ever you wish to call out the feedcount like so:

 <h1>I have <i><?php feedburner_stats('co/VazT', 'circulation'); ?></i> subscribers!<h1>

I hope you find this function of use, Here is a demo of it in action. A special thanks goes out to @t1gr0u for helping me clean up the function. If you have any thoughts or feedback, please feel free to share it.


About the author

My name is Philip Beel. I have four years commercial experience in front end web development. My disciplines include XHTML, CSS, PHP, MYSQL, Smarty and javascript. I am also a keen advocate of the jQuery framework.

Read more posts by


4 Comments on The PHP Feedburner Function

    Leave a comment


    Had a lovely evening at crazy bear with @keepjacqui another year older!

    Follow me