Access Feedburner Stats With PHP

In order to fully customize Feedburner, many developers want to display their feed count in a special way. Whether it is through a different graphic image or just a simple number, not everyone wants to use Feedburner’s built-in chicklet.

Feedburner

While adding feed statistics to the website theme here at ResourceMania, we used the Feedburner API to get access to the subscriber count. In the following article, we will show you how to access Feedburner stats with PHP.

Just paste this simple function into your code to access statistics:

// function to obtain the subscriber count of a Feedburner RSS Feed
function getSubscriberCount( $name ) {
	// Find the URL to query and get its contents
	$url = "http://api.feedburner.com/awareness/1.0/GetFeedData?uri=" . $name;
	$info = @file_get_contents( $url );

	// If no data was returned, return 0 subscribers
	if( !$info ) {
		return 0;
	}
	// otherwise
	else {
		// match the subscriber count with regular expressions
		preg_match( '/circulation="(\d+)"/', $info, $matches );

		// if there was a match, get it and return it
		if( $matches[1] )
			return intval( $matches[1] );

		// otherwise, return 0 subscribers
		return 0;
	}
}

It queries Feedburner and obtains XML information. Using regular expressions, it parses this information and finds the subscriber count.

XML

To use it, simply plug in you feed name and echo the result. For example, if your feed is found at feeds2.feedburner.com/MyFeedName, you would pass “MyFeedName” as the parameter:

// print out the subscriber count
echo getSubscriberCount( "MyFeedName" );

That’s all there is to it. Good luck.

0 Response to “Access Feedburner Stats With PHP”


  • No Comments

Leave a Reply