• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

PHP newline

Ampsonic

Gawd
Joined
Apr 18, 2004
Messages
830
Delving into the world of PHP for the first time. I'm trying to do some basic file output stuff, here's my code.

Code:
<?php
$file = fopen("test.txt", "a");
fwrite($file,$comment);
?>

Works fine, except I can't get it to insert a newline. Any attempt at escape characters are ignored and put into the file.

Thanks,
Nick
 
That piece of code looks like it should work but you dont show us how you're initializing $comment.

Code:
$comment = "hello\nworld";

also, depending on your platform, you may need to use

Code:
$comment = "hello\r\nworld";

also, if you're trying to view the file via a webbrowser, you may need to use <br /> for your breaks instead...but since you're outputing to txt, i doubt this is the problem.

--KK
 
Thanks, got it now, i think the problem is that i was using ' instead of " to surround my \n


Nick
 
That is exactly why your code failed, ' " and ` (single-quote, double quote, and backtick) all have different semantic meanings for a piece of code. Oreilly's PHP book can give you the gory details, but it is largely inheirited from perl's quoting syntax.
 
Back
Top