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("".
  3. "?callback=?&url=".urlencode($url));
  4. preg_match("#(\"count\"):([0-9]*)#",$s,$ar);
  5. return isset($ar[2]) ? $ar[2] : 0;
  6. }
  8. echo readTwitterShares("");


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.