Compare Two Flat E-mail Lists with PHP

So here’s how I parsed to flat files with e-mail addresses (nothing special about it)

approved_emails.txt has the following emails in it:

  • email1@email.com
  • email2@email.com

check_emails.txt is composed of:

  • email1@email.com
  • email3@email.com
  • email4@email.com

My php file that I’m actually running from a command prompt is check_email_addresses.php

< ? $approved_emails = file(“approved_emails.txt”); $check_emails = file(“check_emails.txt”); foreach ($check_emails as &$value) { if (!in_array($value,$approved_emails)) { echo $value; } } ?>The output of the code will be:

  • email3@email.com
  • email4@email.com

You could pipe this out to another file if you needed it for later use.

php check_email_addresses.php > delete_these_addresses.txt