简体   繁体   English

如何使用PHP从csv文件中提取所有电子邮件?

[英]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. 我需要邮寄我的客户,为此我有一个包含客户数据的csv文件,包括CSV文件中的电子邮件。

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) 如何使用PHP读取所有电子邮件地址,将它们放入数组,或将它们插入到文本文件中(只是我可以使用的格式)

The CSV looks like this: (sample record) CSV如下所示:(样本记录)

"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). 该文件包含超过3000条记录(CSV文件)。 How can I find/get all emails ..@.. in PHP? 如何在PHP中查找/获取所有电子邮件.. @ ..

Thank you 谢谢

Just loop through the CSV and grab the appropriate field. 只需循环访问CSV并抓取相应的字段即可。 You use fgetcsv() to do this: 您使用fgetcsv()执行此操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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