Question

I've tried using the 'number_format' in the code below but did't return the intended result. This counter works, all I want to do is simply show a dot or comma after the thousands change. So instead of 1000 that shows now, to show 1.000.

There's also a related txt file in the same folder where the count data is stored-just saying.

<?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); 

?>
Was it helpful?

Solution 2

Preety straight forward answer for you...

<?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); 
?>

OTHER TIPS

in short http://php.net/manual/en/function.number-format.php

in long:

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

Try number_format()

echo "<p>Pageview: " . number_format($count,3,'.') . "</p>";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top