How to display likes in facebook style in php
Use the following function to format facebook likes, comments count
if(!function_exists(‘format_num’)){
function format_num($n) {
$arr = array(“K”, “M”, “G”, “T”);
$out = “”;
while ($n >= 1000 && count($arr ) > 0) {
$n = $n / 1000.0;
$out = array_shift($arr );
}
return round($n, max(0, 3 – strlen((int)$n))) .” $out”;
}
}
To use this function in codeigniter add this function in
system/helper/url_helper.php file
will give like counts in facebook style.
Ex 100 likes
1000 likes = 1 K
10000 likes = 10 K