Jump to content


Photo

Spliting up numbers?


  • Please log in to reply
1 reply to this topic

#1 Rawns

Rawns
  • Members
  • PipPip
  • Member
  • 10 posts
  • LocationUK

Posted 09 September 2006 - 05:28 PM

This code counts how many times a page has been opened. The number is saved in 'hitcounter.txt' and displays the number on a page like this:

12345678

I would like them to be displayed like this:

12,345,678

How can I do this?

This is the code used:

<?php
	$count_my_page = ("hitcounter.txt");
	$hits = file($count_my_page);
	$hits[0] ++;
	$fp = fopen($count_my_page , "w");
	fputs($fp , "$hits[0]");
	fclose($fp);
	echo $hits[0];
?>


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 09 September 2006 - 05:39 PM

See http://www.php.net/number_format

$hits = 1234567;

echo number_format($hits, 0);

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users