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!

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.).

Archived

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

×
×
  • 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.