How To Calculate Facebook Like, Twitter, Pin It and Google Plus Count With PHP

For Facebbok Like count,

$url = “”;
$json_string = file_get_contents(‘’.$url);
$xml = (array)simplexml_load_string($json_string);


For Twitter count,

$url = “”;
$json_string = file_get_contents(‘’.$url.’&callback=?%27&callback=?&format=json’);
$json = json_decode($json_string, true);


For Pin It count,

$url = “”;
$json_string = file_get_contents(‘’.$url);
$json = json_decode(str_replace(‘)’,”,str_replace(‘(‘,”,$json_string)), true);


For Google Plus count,

$url = “”;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, “”.urlencode($url));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$html = curl_exec ($curl);
curl_close ($curl);
$doc = new DOMDocument();
echo $counter->nodeValue;


Thats it!!


  1. and .. .how to use it ??

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: