PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
tail
Forum Commoner
Posts: 66 Joined: Sat Oct 01, 2005 4:42 pm
Location: NJ
Post
by tail » Thu Jun 15, 2006 11:46 pm
Here's the code I'm using:
Code: Select all
<?php
$filename = 'visitors.txt';
$screenname = $_GET ['screenname'];
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $screenname) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($screenname) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?>
But the problem is I need to have a line break after every value that get's put in the file. Any help?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jun 16, 2006 12:05 am
Code: Select all
"\n"
// or
PHP_EOL // a constant in "later" versions of phpNote, \n must be in double quotes to be processed.
tail
Forum Commoner
Posts: 66 Joined: Sat Oct 01, 2005 4:42 pm
Location: NJ
Post
by tail » Fri Jun 16, 2006 12:11 am
Where would I put that?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jun 16, 2006 12:14 am
they would need to be added while calling
fwrite()
tail
Forum Commoner
Posts: 66 Joined: Sat Oct 01, 2005 4:42 pm
Location: NJ
Post
by tail » Fri Jun 16, 2006 12:17 am
This isn't working. Can you place it where it needs to be? That would be great.
Code: Select all
<?php
$filename = 'visitors.txt';
$screenname = $_GET ['screenname'];
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $screenname, "\n") === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($screenname) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?>
printf
Forum Contributor
Posts: 173 Joined: Wed Jan 12, 2005 5:24 pm
Post
by printf » Fri Jun 16, 2006 12:22 am
this...
Code: Select all
if (fwrite($handle, $screenname, "\n") === FALSE) {
should be....
Code: Select all
if (fwrite($handle, $screenname . "\n") === FALSE) {
you had a comma after the $screenname, it need to be a dot/period, if on Windows you also need to use "\r\n", instead on just "\n" for linux/unix and just "\r" for OSMac!
pif!
tail
Forum Commoner
Posts: 66 Joined: Sat Oct 01, 2005 4:42 pm
Location: NJ
Post
by tail » Fri Jun 16, 2006 12:26 am
Thank you