horizontal Posted October 12, 2009 Share Posted October 12, 2009 Hi Everyone! I'm new to this forum and a newbie with PHP - I'm glad I found this site - I hope to learn a lot! For my first and hopefully one of few questions, lol.. I told my boss i'd help him out with making a script to sort a txt file he has with 92 pages of e-mail addresses into something organized. Before i work out how to check for duplicates, so on and so forth - I'm trying to do the basics. I realise this is wrong <?php $emails=fopen('test.txt','r'); $newlist=fopen('test2.txt','a'); while(! feof($emails)) { $newline=fgets($emails); $newchar=fgetc($newline); if ($newchar==" ") fseek($newlist,0,seek_end); else { $addy = fnmatch ("*@*.*",$newline); fwrite($newlist,$addy); } } ?> I'm just trying to get the script to store a line in the variable and then go by character until it hits a space and move down to the next line to write the next e-mail it finds - I think the sequence im searching for is also a bit off. I understand I will need a loop of some sort so all the char's in the $newline character are viewed, can someone please help me out - I feel i'm so close to doing this! Quote Link to comment https://forums.phpfreaks.com/topic/177374-i-think-im-using-the-syntax-incorrectly/ Share on other sites More sharing options...
cags Posted October 12, 2009 Share Posted October 12, 2009 Can you give an example (obviously using fake e-mail addresses) or what the file looks like? Quote Link to comment https://forums.phpfreaks.com/topic/177374-i-think-im-using-the-syntax-incorrectly/#findComment-935357 Share on other sites More sharing options...
horizontal Posted October 13, 2009 Author Share Posted October 13, 2009 Thanks for the response. Here is an example of what the file looks like. blahsflkj@lksdjf.com, al34098sj@s09s3js.com, j123ljkw.com, <4834@jdjd.com>4834@jdjd.com, sdlkfjj@jslela.com It's basically 92 pages of that. Quote Link to comment https://forums.phpfreaks.com/topic/177374-i-think-im-using-the-syntax-incorrectly/#findComment-935834 Share on other sites More sharing options...
mikesta707 Posted October 13, 2009 Share Posted October 13, 2009 if i wanted to get an array of the different emails (assuming that every single email was seperated by a comma) I would do this $content = file_get_contents('email.txt'); $emails = array(); $emails = explode(',', $content); array_map("trim", $emails);//this just removes trailing or leading whitespace from all the entries Quote Link to comment https://forums.phpfreaks.com/topic/177374-i-think-im-using-the-syntax-incorrectly/#findComment-935842 Share on other sites More sharing options...
horizontal Posted October 13, 2009 Author Share Posted October 13, 2009 what if some of the emails are seperated like this, blah@blah.com, <blah@sdk.net>blah@sdk.net, etc ? Quote Link to comment https://forums.phpfreaks.com/topic/177374-i-think-im-using-the-syntax-incorrectly/#findComment-935854 Share on other sites More sharing options...
mikesta707 Posted October 13, 2009 Share Posted October 13, 2009 well as long as every email between the commas is ONE email, than its fine. if you want to take "<blah@sdk.net>blah@sdk.net" and split that into two things, then you will have to change the code up Quote Link to comment https://forums.phpfreaks.com/topic/177374-i-think-im-using-the-syntax-incorrectly/#findComment-935858 Share on other sites More sharing options...
horizontal Posted October 13, 2009 Author Share Posted October 13, 2009 I would prefer not to have anything within < > brackets added to the array.. I am way over my head with this - sorry if I'm asking some real amature questions.. Quote Link to comment https://forums.phpfreaks.com/topic/177374-i-think-im-using-the-syntax-incorrectly/#findComment-935861 Share on other sites More sharing options...
mikesta707 Posted October 13, 2009 Share Posted October 13, 2009 ok, we in that case, you can use regular expressions to replace the brackets, and anything between with nothing. I'm not very good with regex, so I dont want to steer you wrong, but try finding a tutorial on regex. Quote Link to comment https://forums.phpfreaks.com/topic/177374-i-think-im-using-the-syntax-incorrectly/#findComment-935866 Share on other sites More sharing options...
gizmola Posted October 13, 2009 Share Posted October 13, 2009 Well let's take mikesta707's code and just add a bit: $content = file_get_contents('email.txt'); $emails = array(); $emails = explode(',', $content); $emails = preg_replace('/]*>/', '', $emails); // strip out all the from the addresses array_map("trim", $emails);//this just removes trailing or leading whitespace from all the entries // Didn't you mention a sort? sort($emails); foreach ($emails as $value) { // write out to your new file } [/code] Quote Link to comment https://forums.phpfreaks.com/topic/177374-i-think-im-using-the-syntax-incorrectly/#findComment-935891 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.