Search code examples
phpcounterpageviews

php add counter with thousands separator


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

?>

Solution

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