普通网友 2013-04-30 04:44
浏览 41

PHP数量为千计,K风格计数Facebook分享

I have a PHP code for the counter but I need to add something to the counter is as follows:

  • 1k
  • 1100k
  • 1200k etc
  • 2k
  • 2100k etc. and
  • 2m
  • 2500m

For now I have this counter done in PHP.

<?php function get_likes($url) {
  $json_string = file_get_contents('http://graph.facebook.com/?ids=' . $url);
  $json = json_decode($json_string, true);
  return intval( $json[$url]['shares'] );
}?>

Show with

<?php echo get_likes(http://url...); ?>
  • 写回答

2条回答 默认 最新

  • drcvvkx914772 2013-04-30 04:53
    关注

    Try passing the value into this simple function:

    function kilomega( $val ) {
        if( $val < 1000 ) return $val;
        $val = (int)($val/1000);
        if( $val < 1000 ) return "${val}k";
        $val = (int)($val/1000);
        return "${val}m";
    }
    
    评论

报告相同问题?