Archived

This topic is now archived and is closed to further replies.

lukeyes

writing to a new line in a file using PHP

Recommended Posts

Hello everyone. As it says in my subject, I'm trying to write to a file in PHP. I use the following code.

		$file_var = fopen("registry.txt", "w");
				
		fputs($file_var, "$numtaken $average\n");
		fputs($file_var, "did you go to another line\n");
		
		fclose($file_var);

 
it writes the data to the file, but the resulting file looks like this 5 10did you go to another line? for some reason the \n character isn't working like it should, any suggestions? thanks, Luke [edited by - lukeyes on July 26, 2003 2:19:36 PM]

Share this post


Link to post
Share on other sites

Try storing your text in a string and adding the length at the end of fputs.

$file_var = fopen("registry.txt", "w");

$str="$numtaken $average\n";
fputs($file_var,$str, strlen($str) );

$str="did you go to another line\n"
fputs($file_var,$str, strlen($str) );

fclose($file_var);

Share this post


Link to post
Share on other sites