PHP计数一千到K风格计数Facebook Share [英] PHP Count round thousand to a K style count Facebook Share

查看:108
本文介绍了PHP计数一千到K风格计数Facebook Share的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP代码的计数器,但我需要添加一些计数器如下:




  • 1k

  • 1100k

  • 1200k等

  • 2k

  • 2100k等

  • 2m

  • 2500m



现在我在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']);
}?>

显示与

 code><?php echo get_likes(http:// url ...); ?> 


解决方案

尝试将值传递给这个简单的函数: p $

  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;
}


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...); ?>

解决方案

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";
}

这篇关于PHP计数一千到K风格计数Facebook Share的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆