New to PHP, Need help Guys. Anyone got a Quick Code.

Here is what I am trying To do.

I have email ids where subscriber subscribes for newsletters. That is good!

Subscribers often change their company in our profession and the email which is subscribed bounces back lets say about 200 of them

Now I have a Extractor program which grabs the bounce back email and Saves it in the nice txt format.

What I am Trying to do is upload the TXT file and Search for all email IDs which are bounce back emails and delete those from the database.
Paste the email IDs in the multiple fields section and delete it from the database.

Any suggestions would be Big help

Look forward for quick good Suggestions


Joe Limboo

Member Avatar

Hello, i dont know how to manage files with PHP, but i found something that will help a lot.

// Get a file into an array.  In this example we'll go through HTTP to get
// the HTML source of a URL.
$lines = file('');

// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
    echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";

It will show you what it has, you only need to put yout .txt file and it will show and you will be able to read it with another function like file_read or something like that, and then use logic.

Thanks For replying quick. I wanted to do this way. I wanted to upload a text File which will almost 200 odd emails and then match that in Email table in Database. If it is then Delete those emails with Entire row.

Let us see how it work with your code

Let me see if I understand: You have a DB table with the emails of each subscriber stored inside? E.g: columns like:

id | email | etc
1 | | blahblahinfo
2 | | blahblahmoreinfo

If there's 500+ email addresses, you probably don't want to copy/paste, so we'll use the fopen method(Note: I'm assuming your program writes each email to a line and uses \n to start a new line):

// Open the file
$filename = "/path/to/file/name.txt";
$file = fopen($filename, "r");
if(!$file) {
   die("Error opening file!");

// Read the file
$file_text = fread($file, filesize($filename));

// Put emails into array by separating them at the line break("\n");
$emails = explode("\n", $file_text);

// Assuming db connection in $con, delete emails
$x = 0;
foreach($emails as $email) {
$query = "DELETE FROM Subscribers WHERE email='$email' LIMIT 1";
mysql_query($query, $con) or die(mysql_error());

// Sleep every 100 queries to lessen server stress
if($x > 100) {
$x = 0;


Note: There may be a more efficient way, but I'm not an SQL master.