2016-01-21 24 views
2

我目前使用這個劇本,讓我的Instagram的追隨者數:Instagram的追隨者計數顯示標點符號

<?php $instagram="https://api.instagram.com/v1/users/31087586/?access_token=31087586.bf7a21a.5af0d01b2ff1472c8d0a077824990111" ; $instagram_follows=j son_decode(file_get_contents($instagram))->data->counts->followed_by; echo $instagram_follows; ?> 

不幸的是,它顯示就像一串數字(即「12345 「),我希望它以」12,345K「的格式顯示。

幫助表示讚賞!

回答

1
$instagram_follows = number_format(instagram_follows); 

echo $instagram_follows; 

或者乾脆

echo number_format($instagram_follows); 

也有是在你的代碼中的錯誤在那裏說:j son

這將工作

<?php 
$instagram="https://api.instagram.com/v1/users/31087586/?access_token=31087586.bf7a21a.5af0d01b2ff1472c8d0a077824990111" ; 
$instagram_follows=json_decode(file_get_contents($instagram))->data->counts->followed_by; echo number_format($instagram_follows) . "K"; 
?> 
0

請張貼任何之前刪除任何憑據! 值爲int,因此您可以使用number_format()

$instagram = "https://api.instagram.com/v1/users/XXXXXXXXX/?access_token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ; 
$instagram_follow = json_decode(file_get_contents($instagram))->data->counts->followed_by; 
$instagram_follows = number_format($instagram_follow, 0, '', ',').'K'; 
echo $instagram_follows;