Jump to content

Checking email exists in .txt file


graham23s

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.