Posted By

math89 on 07/20/10


Tagged

rss feed feedburner


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

osirisinternet


Get your average Feedburner subscribers


 / Published in: PHP
 

URL: http://www.catswhocode.com/blog/10-life-saving-php-snippets

  1. function get_average_readers($feed_id,$interval = 7){
  2. $today = date('Y-m-d', strtotime("now"));
  3. $ago = date('Y-m-d', strtotime("-".$interval." days"));
  4. $feed_url="https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=".$feed_id."&dates=".$ago.",".$today;
  5. $ch = curl_init();
  6. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  7. curl_setopt($ch, CURLOPT_URL, $feed_url);
  8. $data = curl_exec($ch);
  9. curl_close($ch);
  10. $xml = new SimpleXMLElement($data);
  11. $fb = $xml->feed->entry['circulation'];
  12.  
  13. $nb = 0;
  14. foreach($xml->feed->children() as $circ){
  15. $nb += $circ['circulation'];
  16. }
  17.  
  18. return round($nb/$interval);
  19. }

Report this snippet  

You need to login to post a comment.