Making a CSV-formatted string
function make_csv_line($values) {
foreach($values as $i => $value) {
if ((strpos($value, ',') !== false) ||
(strpos($value, '"') !== false) ||
(strpos($value, ' ') !== false) ||
(strpos($value, "\t") !== false) ||
(strpos($value, "\n") !== false) ||
(strpos($value, "\r") !== false)) {
$values[$i] = '"' . str_replace('"', '""', $value) . '"';
}
}
return implode(',', $values) . "\n";
}
Related examples in the same category