PC Nerd Posted December 18, 2007 Share Posted December 18, 2007 Hi, Im looking for a way to write to a CSV file. I can get the writing working, but i cant seem to find out how to get the records seperated. at the moment the firlds are placed correctly "value, value, value" - however the next record only continues on the same line when veiwed in MS Office Excel. How can I create the newline? thanks Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted December 18, 2007 Author Share Posted December 18, 2007 *** UPDATE: echoing: "\n"; at the end of the record foesnt work - it actually echos out as the characters "\" and "n". is this because o fht encoding or somethign eg ASCI etc??? thanks Quote Link to comment Share on other sites More sharing options...
btherl Posted December 18, 2007 Share Posted December 18, 2007 Try echoing "\n" instead of '\n'. Double quotes are necessary for those special characters. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted December 18, 2007 Author Share Posted December 18, 2007 <?php $lastname = "ME"; $firstname = "NAME"; $email = "email@domain.com"; if(is_writable('TEST.csv')) { $fp = fopen('TEST.csv','a'); $content = "$lastname,$firstname,$email\n"; fwrite($fp,$content); fclose($fp); } ?> thats what ive got - and its working. Thanks Thanks Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted December 18, 2007 Share Posted December 18, 2007 I changed this and it is working for me, you should give a try $content = "$lastname,$firstname,$email" . "\r\n"; Quote Link to comment Share on other sites More sharing options...
btherl Posted December 18, 2007 Share Posted December 18, 2007 That looks fine then.. how did you find that it was printing \ and n instead of \n? Oh, and try neon's suggestion \r\n is the windows end-of-line Quote Link to comment 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.