• Advertisement

Archived

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

writing to a new line in a file using PHP

This topic is 5320 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement

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

  • Advertisement