note 24033 added to function.fwrite
| From: | edg at spymac dot com | Date: | Sun, 04 Aug 2002 20:14:10 +0000 |
| Subject: | note 24033 added to function.fwrite | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-34275@lists.php.net to get a copy of this message | ||
My grapicaly optimised version :
# Builds a basic page counter with graphical interface from a text file!
#Credits :george.johnson11@ntlworld.com for the orginal counter
#edg@spymac.com for graphical interface
# Filename
$cnt_file = "counter.txt";
#Check to see if we are being sent a "Reset" request
if ($_GET['reset']==1) {
#We are, so let's reset the counter
#open up the file with write access
$tmpfile = fopen($cnt_file,"w");
# Write our $string with 1. (1 not 0 because then the first visitor would be "0")
$string = 1;
$fp = fwrite($tmpfile,$string);
# Close file and close our if
fclose($tmpfile);
}
else {
# Read single line into a string
$string = implode("", file($cnt_file));
#Get the length of the string for our 'for' loop
$length = strlen($string)-1;
#Run a for loop to produce the <IMG> tag for the HTML
for ($i=0; $i <= $length; $i++) {
print ("<IMG SRC=\"");
print ($string[$i]);
print (".jpg\">");
}
# Add one to current value
$string++;
# Open file for write, not append!
$tmpfile = fopen($cnt_file,"w");
# Write the new value back to the string
$fp = fwrite($tmpfile,$string);
# Close file
fclose($tmpfile);
}
You just need 0-9.jpg of whatever flavour you want. Also now with a neat little reset function.
edg
--
http://www.php.net/manual/en/function.fwrite.php
http://master.php.net/manage/user-notes.php?action=edit+24033
http://master.php.net/manage/user-notes.php?action=delete+24033
http://master.php.net/manage/user-notes.php?action=reject+24033