11 08 2015

29. 转发数量

使用这个 PHP 片段可以检测你的页面 URL 有多少转发数量

?
1
2
3
4
5
6
7
8
9
10
function tweetCount($url) {
    $content = file_get_contents("http://api.tweetmeme.com/url_info?url=".$url);
    $element = new SimpleXmlElement($content);
    $retweets = $element->story->url_count;
    if($retweets){
        return $retweets;
    } else {
        return 0;
    }
}

语法:

?
1
2
3
4
5
<?php
$url = "http://blog.koonk.com";
$count = tweetCount($url);
return $count;
?>
发表评论