chadrt Posted February 2, 2015 Share Posted February 2, 2015 (edited) Ok so I have this script that I wrote and it works really good. I wanted to display the number of records in a table and since the db only changes once per day I thought I would put the couner on the back end. I have this script that changes the value of the text file every day. But I would love it if it outputted with commas. Now it reads: 1234070 Want it to read: 1,234,070 Any thoughs? #!/usr/bin/php -q <?php $username=""; // READONLY USER USED HERE AND AUTH'D ON LOCALHOST ONLY $password=""; $database=""; $dbhost=""; mysql_connect($dbhost,$username,$password); @mysql_select_db($database) or die( "Unable to connect to database please try again!"); $counthd=mysql_query("SELECT count(*) as total from HD"); $hdtotal=mysql_fetch_assoc($counthd); $dbcount = $hdtotal['total']; echo ""; $myFile = "dbcounter.txt"; $fh = fopen($myFile, 'w'); fwrite($fh, "$dbcount"); fclose($fh); ?> Edited February 2, 2015 by chadrt Quote Link to comment https://forums.phpfreaks.com/topic/294304-change-output-of-a-php-cli-file-add-commas/ Share on other sites More sharing options...
Solution QuickOldCar Posted February 2, 2015 Solution Share Posted February 2, 2015 http://php.net/manual/en/function.number-format.php Quote Link to comment https://forums.phpfreaks.com/topic/294304-change-output-of-a-php-cli-file-add-commas/#findComment-1504525 Share on other sites More sharing options...
chadrt Posted February 2, 2015 Author Share Posted February 2, 2015 That worked very well thank you! Quote Link to comment https://forums.phpfreaks.com/topic/294304-change-output-of-a-php-cli-file-add-commas/#findComment-1504526 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.