Alice Posted March 1, 2013 Share Posted March 1, 2013 Hi, This is probably something very simple for most of you, but I'm very new to php coding, so thanks in advance for your help! All I'm needing to do is have a one field form on my site that will append the data to a text file. I have it working, however it enters data into the file immediately after the previous data without a comma or a line break. This will make it very hard to export later on. Here is the code I'm using $fh = fopen("email.txt", "a");fwrite($fh, $email);fclose($fh); What can I do here to have it enter a comma or a line break? Link to comment https://forums.phpfreaks.com/topic/275090-simple-form-that-appends-to-a-text-file/ Share on other sites More sharing options...
Alice Posted March 1, 2013 Author Share Posted March 1, 2013 I think I figured it out. Here is what I added. If someone could let me know this is correct of if there is a better way? It seems to be working for now. $fh = fopen("formdata.txt", "a"); fwrite($fh, "$email\r\n"); fclose($fh); Thanks! Link to comment https://forums.phpfreaks.com/topic/275090-simple-form-that-appends-to-a-text-file/#findComment-1415854 Share on other sites More sharing options...
jcbones Posted March 2, 2013 Share Posted March 2, 2013 That is fine, you could also use: file_put_contents('formdata.txt',$email,FILE_APPEND | FILE_EX); Link to comment https://forums.phpfreaks.com/topic/275090-simple-form-that-appends-to-a-text-file/#findComment-1415922 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.