-2

I have the csv file mail.csv I have the text as below:

d,2012-08-24 00:00:57+0200,2012-08-24 00:00:45+0200,noreply@news.camera-factice.com,...
d,2012-08-24 00:00:57+0200,2012-08-24 00:00:45+0200,noreply@118-bonsplans.com,toulouse@texa.fr,...
b,2012-08-24 00:00:57+0200,2012-08-22 23:59:31+0200,noreply@lemeilleur-duweb.com,...
b,2012-08-24 00:00:57+0200,2012-08-22 23:59:31+0200,noreply@lemeilleur-duweb.com,...

I want to get only mail.exaple:noreply@lemeilleur-duweb.com.And if the mail have 2 or more mail are the same, I want to take only one mail.I have the code php as below:

<?php       
    $handle = fopen('acct-2012-08-24-0001.csv', 'r');
    $mail = 'noreply@118-bonsplans.com';
    $respon = 'fail';
    $Totalcounter = 0;
    $mailFail = 0;
    $percentage = 0;
    $data[]="";
    if ($handle) {
        while (($buffer = fgets($handle, 4096)) !== false) {
         if (stristr($buffer, '118-bonsplans.com')) $Totalcounter += 1;
         if(($data = fgetcsv($handle, 1000, ",")) !== FALSE);
         if (stristr($buffer, $mail) && stristr($buffer,$respon)) $mailFail += 1;

    }   fclose($handle);

    //echo $data[3];
    }
     $percentage = ($mailFail/$Totalcounter)*100;
     echo '<table border="1px">';
     echo "<tr><td>Dormain</td><td>Total</td><td>Mail Fail</td><td>Percentage</td></tr>";
     echo "<tr><td>".$data[3]."</td><td>".$Totalcounter."</td><td>".$mailFail."</td><td>".$percentage."</td></tr>";
     echo '</table>';


?>

Note For this code I wrote that if(($data = fgetcsv($handle, 1000, ",")) !== FALSE); to get the mail from the csv file.but it dose not work.

Anyone help me please, Thanks

user1606816
  • 381
  • 1
  • 3
  • 6

1 Answers1

0

From what I can gather - you're trying to stop your script from outputting duplicate email addresses. The fix for this is pretty easy. What you need to do is setup an array that will store the email addresses that you will be outputting. Before you add an email to this array, you'll need to check to see if the email hasn't already been added to it before. If it has already been added, don't add. If it hasn't already been added, do add. This check can be done with the help of the in_array() function.

By doing this, you'll be left with an array that won't hold any duplicate email addresses.

Wayne Whitty
  • 19,513
  • 7
  • 44
  • 66