简体   繁体   中英

How can I extract all emails from csv file using PHP?

I need to mail my customers, and for this I have a csv file containing the customers data including emails in CSV file.

How can I use PHP to read all email addresses, put them into array, or insert them into text file (just a format I can use)

The CSV looks like this: (sample record)

"Date","Ref #","Time","Customer","Country","Email","Product","Product ID","Contract","Contract ID","Payment Type","Frequency","Referrer","Qty","Sale type","Adds","Total","Price","Plimus Commission","Affiliate Commssion (%)","Affiliate Commssion ($)","Tracking Id","CUSTOM1","CUSTOM2","CUSTOM3","CUSTOM4","CUSTOM5","Subscription ID","Target Balance","PayPal Comm.(main contracts)","PayPal Transaction ID","Original PayPal Transaction ID","PayPal email address"
"06/06/2008","19796287","04:06:29"," Mehmet Özekinci","Turkey","mhmtozek@gmail.com","Website Templates Pack","190830","xxxxxxxxxxx","1941602","PAYPAL","Once","xxxxxxxxxxxx","1","CHARGE","0","25","25","0","n/a","n/a"," "," "," "," "," "," "," ","xxxxx Account"," "," "," ","k_anafor56@hotmail.com"

The file contains more than 3000+ records (CSV file). How can I find/get all emails ..@.. in PHP?

Thank you

Just loop through the CSV and grab the appropriate field. You use fgetcsv() to do this:

$emails = array();
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $emails[] = $data[5];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM