Signatur
fputcsv(resource $stream, array $fields, string $separator = ",", string $enclosure = "\"", string $escape = "\", string $eol = "\n"): int|false
Beschreibung
Excel bevorzugt Semikolon als Separator und ISO-8859-1: fputcsv($fh, $row, ';') + fwrite($fh, "\xEF\xBB\xBF") als BOM.
Parameter
| Name | Typ | Default | Beschreibung |
|---|---|---|---|
| $stream Pflicht | resource | — | Handle. |
| $fields Pflicht | array | — | Werte. |
| $separator | string | "," | Feld-Trenner. |
| $enclosure | string | '"' | Text-Klammer. |
Rückgabewert
Typ
int|false
Beschreibung
Geschriebene Bytes.
Beispiele
CSV Export
<?php
$fh = fopen('users.csv', 'w');
fputcsv($fh, ['ID', 'Name', 'E-Mail']);
fputcsv($fh, [1, 'Anna', 'anna@x.de']);
fclose($fh);