Jump to content

[SOLVED] help: question about writing records to txt file


jayyu317

Recommended Posts

I have the the question when I write records to txt file. I want to use following script

 

$outputstring = $date."\t".$tireqty." tires\t".$oilqty." oil\t" $sparkqty." spark plugs\t\$".$total ."\t". $address."\n";

$fp = fopen("orders.txt", 'a');

flock($fp, LOCK_EX);

fwrite($fp, $outputstring);

flock($fp, LOCK_UN);

fclose($fp);

 

to add records to orders.txt file and show records as this way:

 

15:42, 20th April 4 tires 1 oil 6 spark plugs $434.00 22 Short St, Smalltown

15:43, 20th April 1 tires 0 oil 0 spark plugs $100.00 33 Main Rd, Newtown

 

 

But after adding, they are in one line:

15:42, 20th April 4 tires 1 oil 6 spark plugs $434.00 22 Short St, Smalltown15:43, 20th April 1 tires 0 oil 0 spark plugs $100.00 33 Main Rd, Newtown

 

I replaced above script with . $address."<br>". But it can not show as what I want, and show "<br>" between records.

 

How can I show the records line by line when writing in the txt file?

 

Thank!

Link to comment
Share on other sites

What are you viewing the file with?

 

If you are using notepad or a web browser, they won't show up...they're still there though.  Notepad won't recognize just a "\n", but requires a "\r\n" to display a new line.  If you are using a browser, remember that browsers ignore whitespace.

 

You can either change it to "\r\n" to display correctly, or open using wordpad instead of notepad (or get a better text editor all together: notepad++, etc.).

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.