chadrt Posted February 2, 2015 Share Posted February 2, 2015 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); ?> 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...
QuickOldCar Posted February 2, 2015 Share Posted February 2, 2015 http://php.net/manual/en/function.number-format.php 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! 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
Archived
This topic is now archived and is closed to further replies.