graham23s Posted August 14, 2010 Share Posted August 14, 2010 Hi Guys, I'm using the following code to write emails to a .txt file: // Write the email to file $leadsFile = "leads/emails.txt"; $fh = fopen($leadsFile, 'a') or die ("can't open leads file!"); $writeData = "$conEM\r\n"; fwrite($fh, $writeData); fclose($fh); which works great, but i can't figure out how to NOT write an email to the .txt file if it's already on it, i'm not using a database for a change i'm stumped lol thanks for any help guys Graham Link to comment https://forums.phpfreaks.com/topic/210724-checking-email-exists-in-txt-file/ Share on other sites More sharing options...
wildteen88 Posted August 14, 2010 Share Posted August 14, 2010 I'd first read the text file using file. Next use in_array to see if the email already exists. For example $leadsFile = "leads/emails.txt"; $emails = file($leadsFile, FILE_IGNORE_NEW_LINES); if(!in_array($conEM, $emails)) { // write email to text file $fh = fopen($leadsFile, 'a') or die ("can't open leads file!"); $writeData = "$conEM\r\n"; fwrite($fh, $writeData); fclose($fh); } Link to comment https://forums.phpfreaks.com/topic/210724-checking-email-exists-in-txt-file/#findComment-1099239 Share on other sites More sharing options...
graham23s Posted August 14, 2010 Author Share Posted August 14, 2010 Thanks wildteen works perfectly cheers mate Graham Link to comment https://forums.phpfreaks.com/topic/210724-checking-email-exists-in-txt-file/#findComment-1099245 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.