Jump to content

New Line Problem


jeffpoulsen

Recommended Posts

I'm having trouble getting the new line \n to work in a simple fwrite line. The code is below:

fwrite($fh,$today)      This Works
fwrite($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.
Link to comment
Share on other sites

[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 Works
fwrite($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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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 :|
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.