Click to See Complete Forum and Search --> : New Line


Mr_Floppy
08-18-2003, 10:49 AM
I am writing to a file with append but the it adds it to the last line. Is there a new line command I can use?

Mr_Floppy

pyro
08-18-2003, 10:51 AM
Yes, \n is the new line character. (or, if you are working with an HTML file, it is, of course, <br>)

Mr_Floppy
08-18-2003, 11:08 AM
I get this error when using "\n"

"Warning: Unexpected character in input: '\' (ASCII=92) state=1"

Mr_Floppy

pyro
08-18-2003, 11:10 AM
Let me see your full code, please.

Mr_Floppy
08-18-2003, 03:09 PM
<?php
$date=date("F j, Y");
$fileloc="guests.txt";
$file=fopen($fileloc,"a") or die("Error. Please go back and try again");
fputs($file,\n$name.":".$date.":".$comment);
fclose($file);
print "Thank you. Please go back.";
?>

Mr_Floppy

Kr|Z
08-18-2003, 03:15 PM
You have to change it to:

fputs($file,"\n".$name.":".$date.":".$comment);

Mr_Floppy
08-18-2003, 04:28 PM
That worked, thanks!

Mr_Floppy

pyro
08-18-2003, 04:30 PM
This might be easier...

fputs($file,"\n$name:$date:$comment");

When using double quotes ("), variables will be read as the value of the variable. It's only with single quotes (') that it will display the actual variable.