jayyu317 Posted December 30, 2007 Share Posted December 30, 2007 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 https://forums.phpfreaks.com/topic/83674-solved-help-question-about-writing-records-to-txt-file/ Share on other sites More sharing options...
hitman6003 Posted December 30, 2007 Share Posted December 30, 2007 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 https://forums.phpfreaks.com/topic/83674-solved-help-question-about-writing-records-to-txt-file/#findComment-425779 Share on other sites More sharing options...
jayyu317 Posted December 30, 2007 Author Share Posted December 30, 2007 I saw the txt files with notepad. It works now with notepad2! Thanks very much! Link to comment https://forums.phpfreaks.com/topic/83674-solved-help-question-about-writing-records-to-txt-file/#findComment-426118 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.