bluemonkey519 Posted May 5, 2012 Share Posted May 5, 2012 Hi All, I am not quite sure if this is possible - but here goes. I have a webpage hit counter that uses PHP and saves the counter totals in .txt files. I have gotten the code to print out the comma (thousand separator) fine on the page, however, I would like to have that comma in the text file also. I display the counters on separate pages using <?php include("file.txt");?> and the counter shows up as "12345" when I'd like it to read the text as "12,345". Basically, I just want that comma written to the actual text file if possible so that when it's included on a web page, it displays the thousands separator. Any help would be great. Thank You! Here is a portion of my code: /* Turn error notices off */ error_reporting(E_ALL ^ E_NOTICE); /* Get page and log file names */ $page = input($_GET['page']) or die('ERROR: Missing page ID'); $logfile = 'logs/' . $page . '.txt'; /* Does the log exist? */ if (file_exists($logfile)) { /* Get current count */ $count = intval(trim(file_get_contents($logfile))) or $count = 0; $cname = 'tcount_unique_'.$page; if ($count_unique==0 || !isset($_COOKIE[$cname])) { /* Increase the count by 1 */ $count = $count + 1; $fp = @fopen($logfile,'w+') or die('ERROR: Can\'t write to the log file ('.$logfile.'), please make sure this file exists and is CHMOD to 666 (rw-rw-rw-)!'); flock($fp, LOCK_EX); fputs($fp, $count); flock($fp, LOCK_UN); fclose($fp); /* Print the Cookie and P3P compact privacy policy */ header('P3P: CP="NOI NID"'); setcookie($cname, 1, time()+60*60*$unique_hours); } /* Is zero-padding enabled? */ if ($min_digits > 0) { $count = sprintf('%0'.$min_digits.'s',$count); } /* Print out Javascript code and exit */ echo "document.write('".number_format($count)."');"; exit(); } else { die('ERROR: Invalid log file!'); } Quote Link to comment https://forums.phpfreaks.com/topic/262107-save-text-file-with-number-format/ Share on other sites More sharing options...
trq Posted May 5, 2012 Share Posted May 5, 2012 What exactly is the problem? Quote Link to comment https://forums.phpfreaks.com/topic/262107-save-text-file-with-number-format/#findComment-1343238 Share on other sites More sharing options...
bluemonkey519 Posted May 5, 2012 Author Share Posted May 5, 2012 What exactly is the problem? I would like the thousands separator to be in the actual .txt file, so that if I display the counter on another page, it shows the comma. I cannot seem to get it to write the thousands separator the actual text file. Quote Link to comment https://forums.phpfreaks.com/topic/262107-save-text-file-with-number-format/#findComment-1343242 Share on other sites More sharing options...
nick561 Posted May 5, 2012 Share Posted May 5, 2012 Thanks bluemonkey519 for this information.I was found this information last 2 weeks..............Thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/262107-save-text-file-with-number-format/#findComment-1343262 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.