1 回答
TA贡献1796条经验 获得超4个赞
也许你想要逐行分离?
// creating dirty and clean file
$clean_emails = fopen(UPLOAD_DIRECTORY . '/clean/' . $file_name_new . '.' . $extension, 'w');
$dirty_emails = fopen(UPLOAD_DIRECTORY . '/dirty/' . $file_name_new . '.' . $extension, 'w');
$unknown_emails = null; // No file yet
// adding headers to them
fputcsv($clean_emails, $headers);
fputcsv($dirty_emails, $headers);
foreach ($results as $row) { // Scan each row
if ($row['result'] === 'valid') {
fputcsv($clean_emails, $row);
} elseif ($row['result'] === 'invalid') {
fputcsv($dirty_emails, $row);
} else { // found something else
if (!isset($unknown_emails)) { // Open file if it was not
$unknown_emails = fopen(UPLOAD_DIRECTORY . '/unknown/' . $file_name_new . '.' . $extension, 'w');
fputcsv($unknown_emails, $headers); // Add headers ?
}
fputcsv($unknown_emails, $row);
}
} // end loop
fclose($clean_emails);
fclose($dirty_emails);
if (isset($unknown_emails)) {
fclose($unknown_emails); // Close 'unknown' if it was opened
}
- 1 回答
- 0 关注
- 125 浏览
添加回答
举报