Emil_RDW Posted April 27, 2011 Share Posted April 27, 2011 Hello everybody! Keep in mind I'm new to PHP but get the basics I'm trying to collect email addresses from a web-form that gets filled out on a website into a simple txt file on the server. The problem is the emails get appended one right after the other with no spaces so it looks like "[email protected]@[email protected]" and so on. What I'm trying to do is either separate them by a comma, or put them on a new line but whatever I try, it will not accept it. Anyway, here is the code that I have: $fp = fopen("/home/fullertr/public_html/email_collector.txt","a"); fwrite($fp,$_POST['visitormail' . "\n"]); fclose($fp); unset($_POST); Thanks for any help! Quote Link to comment https://forums.phpfreaks.com/topic/234850-new-line-when-appending-a-txt-file-with-php/ Share on other sites More sharing options...
fugix Posted April 27, 2011 Share Posted April 27, 2011 could you append a break onto your fwrite() fwrite($fp,$_POST['visitormail' . " <br /> \n"]); Quote Link to comment https://forums.phpfreaks.com/topic/234850-new-line-when-appending-a-txt-file-with-php/#findComment-1206894 Share on other sites More sharing options...
Emil_RDW Posted April 27, 2011 Author Share Posted April 27, 2011 nope it didn't work. Actually that doesn't even save anything into the txt file. Quote Link to comment https://forums.phpfreaks.com/topic/234850-new-line-when-appending-a-txt-file-with-php/#findComment-1206920 Share on other sites More sharing options...
PFMaBiSmAd Posted April 27, 2011 Share Posted April 27, 2011 That's because that code is invalid and produces an error. Exactly how are you displaying the data where it ends up being all on one line? In an editor? On a web page? Quote Link to comment https://forums.phpfreaks.com/topic/234850-new-line-when-appending-a-txt-file-with-php/#findComment-1206924 Share on other sites More sharing options...
fugix Posted April 27, 2011 Share Posted April 27, 2011 sorry it didn't work...just a shot in the dark..was worth a shot Quote Link to comment https://forums.phpfreaks.com/topic/234850-new-line-when-appending-a-txt-file-with-php/#findComment-1206929 Share on other sites More sharing options...
Emil_RDW Posted April 27, 2011 Author Share Posted April 27, 2011 sorry it didn't work...just a shot in the dark..was worth a shot Actually that helped me out! I modified it to be on it's own and this actually works: $fp = fopen("/home/fullertr/public_html/email_collector.txt","a"); fwrite($fp,$_POST[" <br /> \n"]); fwrite($fp,$_POST['visitormail']); fclose($fp); unset($_POST); Thanks a lot! Now I have them going to a new line. Now how can I separate them by a comma instead of a new line? PFMaBiSmAd, I'm viewing the text file in the browser by going to the server.com/email.txt Quote Link to comment https://forums.phpfreaks.com/topic/234850-new-line-when-appending-a-txt-file-with-php/#findComment-1206936 Share on other sites More sharing options...
fugix Posted April 27, 2011 Share Posted April 27, 2011 try using the implode() function on your post data Quote Link to comment https://forums.phpfreaks.com/topic/234850-new-line-when-appending-a-txt-file-with-php/#findComment-1206940 Share on other sites More sharing options...
Emil_RDW Posted April 27, 2011 Author Share Posted April 27, 2011 I got it! $fp = fopen("/home/fullertr/public_html/email_collector.txt","a"); fwrite($fp,$_POST['visitormail']. '; '); fclose($fp); unset($_POST); Thanks guys for all the help! Quote Link to comment https://forums.phpfreaks.com/topic/234850-new-line-when-appending-a-txt-file-with-php/#findComment-1206942 Share on other sites More sharing options...
fugix Posted April 27, 2011 Share Posted April 27, 2011 awesome.. Quote Link to comment https://forums.phpfreaks.com/topic/234850-new-line-when-appending-a-txt-file-with-php/#findComment-1206945 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.