Counting how many times a web link has been shared on Twitter


/ Published in: PHP
Save to your folder(s)

Here is a function that read the number of times a url is shared on twitter.


Copy this code and paste it in your HTML
  1. function readTwitterShares($url) {
  2. $s = file_get_contents("http://urls.api.twitter.com/1/urls/count.json".
  3. "?callback=?&url=".urlencode($url));
  4. preg_match("#(\"count\"):([0-9]*)#",$s,$ar);
  5. return isset($ar[2]) ? $ar[2] : 0;
  6. }
  7.  
  8. echo readTwitterShares("http://www.dailybest.it");

URL: http://www.barattalo.it/2012/10/19/how-many-times-a-web-link-has-been-shared-on-twitter/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.