2013-05-07 51 views
0

我有一个php脚本,它使用Youtube API来回应Youtube视频的查看次数。不过,我希望在数千甚至更多的观看次数中添加逗号。以四位或更多位数的数字添加逗号

我的代码如下:

$JSON = file_get_contents('https://gdata.youtube.com/feeds/api/videos/XQu8TTBmGhA?v=2&alt=json'); 
$JSON_Data = json_decode($JSON); 
$views = $JSON_Data->{'entry'}->{'yt$statistics'}->{'viewCount'}; 
echo $views; 

任何帮助,将不胜感激!

+1

你想[number_format()](http://us3.php.net/manual/en/function.number-format.php) – cpilko 2013-05-07 14:25:30

回答

0

使用此

echo number_format($views, 2, '.', ','); 
相关问题