php添加千位分隔符的计数器

时间:2013-11-12 11:24:30

标签: php counter pageviews

我尝试在下面的代码中使用'number_format',但没有返回预期的结果。这个计数器有效,我想做的只是在数千个变化后显示一个点或逗号。因此,而不是现在显示的1000,显示1.000。

在存储计数数据的同一文件夹中还有一个相关的txt文件 - 只是说。

<?php 

$fp = fopen("counters/counterlog.txt", "r"); 

$count = fread($fp, 1024); 

fclose($fp); 

$count = $count + 1; 

echo "<p>Pageview: " . $count . "</p>"; 

$fp = fopen("counters/counterlog.txt", "w"); 

fwrite($fp, $count); 

fclose($fp); 

?>

3 个答案:

答案 0 :(得分:1)

简而言之 http://php.net/manual/en/function.number-format.php

长:

echo "<p>Pageview: " . number_format($count) . "</p>";

答案 1 :(得分:0)

尝试number_format()

echo "<p>Pageview: " . number_format($count,3,'.') . "</p>";

答案 2 :(得分:0)

Preety直接回答你......

<?php
$fp = fopen("counters/counterlog.txt", "r"); 
$count = fread($fp, 1024); 
fclose($fp); 
$count = $count + 1; 
echo "<p>Pageview: " . number_format($count) . "</p>"; // <===
$fp = fopen("counters/counterlog.txt", "w"); 
fwrite($fp, $count); 
fclose($fp); 
?>