I am trying to add a Twitter count number and a Feedburner count number but when I combine the two with basic addition, it fails! If I get the valkues and print them seperatley it works fine, just will not let me add the two...
$twitCnt = twitter_subscribers(TWITTER_USERNAME); $feedCnt = feed_subscribers(FEEDBURNER_USERNAME); $totalCnt = $twitCnt + $feedCnt; echo $totalCnt; Assume that $twitCnt is = 2000 and $feedCnt is = 1000
Now when I try to add the 2 instead of getting 3000 I will get the $feedCnt value + 1 = 1001 instead of 3000
I am currently stumped, If I print the $twitCnt and the $feedCnt they show the correct amounts, however when I add the 2 in my code, the $twitCnt is shown as = 1 instead of it's actual value.
Any ideas what would cause this?
Update after running var_dump($twitCnt, $feedCnt)
string(5) "3,000" object(SimpleXMLElement)#238 (1) { [0]=> string(5) "1,000" } Also the Functions for getting the stats...
function twitter_subscribers($username = 'yourname'){ $count = get_transient('twitter_count'); if ($count != false){ return $count; }else{ $count = 0; $url = 'http://api.twitter.com/1/users/show.xml?screen_name='. $username; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); $xml = new SimpleXMLElement($data); $count = $xml->followers_count; $count = (float) $count; $count = number_format($count); set_transient('twitter_count', $count, 21600); // 6 hour cache return $count; } } function feed_subscribers($username = 'yourname') { $feed_url = 'http://feeds.feedburner.com/' . $username; $count = get_transient('rss_count'); if ($count != false) return $count; $count = 0; $data = wp_remote_get('http://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=' . $feed_url . ''); if (is_wp_error($data)) { return 'error'; } else { $body = wp_remote_retrieve_body($data); echo $body; $xml = new SimpleXMLElement($body); $status = $xml->attributes(); if ($status == 'ok') { $count = $xml->feed->entry->attributes()->circulation; } else { $count = 300; // fallback number } } set_transient('rss_count', $count, 21600); // 6 hour cache//60*60*24 return $count; }
var_dump($twitCnt); var_dump($feedCnt);.var_dump($twitCnt, $feedCnt)to check what they are first.var_dumpabovenumber_format()before you do any manipulation of numbers. Only use it when displaying them. Not sure where the comma is coming from in your feedburnercirculationattribute. This number is not meant to be formatted according to the docs.