note 54506 added to function.fwrite
| From: | james at nicolson dot biz | Date: | Wed, 06 Jul 2005 15:09:22 +0000 |
| Subject: | note 54506 added to function.fwrite | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91536@lists.php.net to get a copy of this message | ||
I could'nt quite get MKP Dev hit counter to work.... this is how I modified it
<?
function hitcount()
{
$file = "counter.txt";
if ( !file_exists($file)){
touch ($file);
$handle = fopen ($file, 'r+'); // Let's open for read and write
$count = 0;
}
else{
$handle = fopen ($file, 'r+'); // Let's open for read and write
$count = fread ($handle, filesize ($file));
settype ($count,"integer");
}
rewind ($handle); // Go back to the beginning
/*
* Note that we don't have problems with 9 being fewer characters than
* 10 because we are always incrementing, so we will always write at
* least as many characters as we read
**/
fwrite ($handle, ++$count); // Don't forget to increment the counter
fclose ($handle); // Done
return $count;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.fwrite.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54506
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54506&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54506&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54506&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54506&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54506&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54506&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54506&report=yes
Search -- http://master.php.net/manage/user-notes.php