2012-02-03 46 views
0

這是我在我的template.php文件中:如何在數字格式顯示數字

function twitter_count() { 
    $pageID = 'TWITTERACCOUNT'; 
    $info = json_decode(file_get_contents('https://api.twitter.com/1/users/show.json?screen_name=' . $pageID .'')); 
    echo $info->followers_count; 
} 

而且我有這樣的顯示塊內的結果:

<?php echo number_format(twitter_count("TWITTERACCOUNT")); ?> 

這是結果:

36170 

回答

1

嘗試

<?php echo number_format(intval(twitter_count("TWITTERACCOUNT"))); ?> 

或者

<?php echo number_format(floatval(twitter_count("TWITTERACCOUNT"))); ?> 

而且還從你的函數刪除回聲。相反,做一個回報。

+0

非常感謝您的回覆。我現在就試試 – TikaL13 2012-02-03 23:37:51

+0

有沒有運氣?我認爲發生了什麼事情是你的函數中的回顯是打印它,即使你在塊中用number_format回顯它,它會直接向stdout執行函數,而number_format正在接收一個空值,從而格式化null,這會導致一個空白字符串。 – 2012-02-06 18:33:59