jeffpoulsen Posted October 24, 2006 Share Posted October 24, 2006 I'm having trouble getting the new line \n to work in a simple fwrite line. The code is below:fwrite($fh,$today) This Worksfwrite($fh,$today"\n") This does not These line are straight out of the book I'm using to learn PHP. I have read about using <br> instead but can't get that to work either. Quote Link to comment https://forums.phpfreaks.com/topic/24922-new-line-problem/ Share on other sites More sharing options...
heckenschutze Posted October 24, 2006 Share Posted October 24, 2006 your not [b]appending[/b] the newline char.In php, to "add strings to strings" you must use the [b].[/b] (fullstop) operator.eg:[code]$hello = "Hello" . " im Heckenschutze";[/code]so in your case:[code]fwrite($fh, $today . "\n") [/code]hth Quote Link to comment https://forums.phpfreaks.com/topic/24922-new-line-problem/#findComment-113585 Share on other sites More sharing options...
redbullmarky Posted October 24, 2006 Share Posted October 24, 2006 [quote author=jeffpoulsen link=topic=112522.msg456741#msg456741 date=1161689379]I'm having trouble getting the new line \n to work in a simple fwrite line. The code is below:fwrite($fh,$today) This Worksfwrite($fh,$today"\n") This does not These line are straight out of the book I'm using to learn PHP. I have read about using <br> instead but can't get that to work either.[/quote]you need to seperate the quotes and the variable. either way here will do:[code]fwrite($fh,$today."\n") // does now!fwrite($fh,"$today\n") // does now![/code] Quote Link to comment https://forums.phpfreaks.com/topic/24922-new-line-problem/#findComment-113586 Share on other sites More sharing options...
jeffpoulsen Posted October 24, 2006 Author Share Posted October 24, 2006 Thanks for the help. It's hard to learn when even the books you use are wrong.Getting a little closer but not there yet. I have tried the above codes and now it doesn't kill the script but what the object the lesson was to write to a flat file and have data go on a new line each time. None of these do that. The entire code for this is below. When I check the file /dwlog.txt it shows the date sent on one line. $today = date('M j g:i a'); $fh = fopen("dwlog.txt","a"); fwrite($fh,$today . "\n"); fclose($fh);By the way fwrite($fh,"$today\n"); did not work.I can see learning PHP is going to be tough. Quote Link to comment https://forums.phpfreaks.com/topic/24922-new-line-problem/#findComment-113593 Share on other sites More sharing options...
heckenschutze Posted October 24, 2006 Share Posted October 24, 2006 Your only writing the date once... the file will look like[code]DATE (NEWLINE)|[/code]eg 2 lines:[code] $today = date('M j g:i a'); $fh = fopen("dwlog.txt","a"); fwrite($fh,$today . "\n");// line 1 fwrite($fh,$today . "\n");// line 2 fclose($fh);[/code]hth :| Quote Link to comment https://forums.phpfreaks.com/topic/24922-new-line-problem/#findComment-113603 Share on other sites More sharing options...
jeffpoulsen Posted October 24, 2006 Author Share Posted October 24, 2006 Thanks Heckenschutze Quote Link to comment https://forums.phpfreaks.com/topic/24922-new-line-problem/#findComment-113614 Share on other sites More sharing options...
True`Logic Posted October 24, 2006 Share Posted October 24, 2006 [code]fwrite($fh,$today . "\n");[/code]or[code]fwrite($fh,"$today\n");[code]work[/code][/code] Quote Link to comment https://forums.phpfreaks.com/topic/24922-new-line-problem/#findComment-113687 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.