我有一个纯文本文件,其中包含以下格式的电子邮件:
"Name Surname" <name.surname@exmaple.com>, 'Name2 Surname2" <name2.surname2@example.com>, ...
注意:每个名称 - 电子邮件对之间有两个空格。整个文件都在一行上。
我怎样才能使用PHP提取数据(只需要电子邮件,但名称也不错)并将其插入SQL数据库(假设$dbc
为SQL连接对象)? / p>
答案 0 :(得分:0)
$file = file_get_contents('emails.txt');
$file = explode(',',$file);
foreach ($file as $recipient) {
$recipient = explode('<',$recipient);
$name = trim($recipient[0]);
$name = str_replace("'",'',$name); // remove apostrophes
$name = str_replace('"','',$name); // remove double quotes
$email = str_replace('>','',$recipient[1]); // remove ">"
echo $name . ' ----- ' . $email . '<br />';
}