Writing CSV and TSV Files
Generate atomic, Excel-friendly delimited files with BOM, encoding, dialect, and injection controls.
Updated
Csv::write()CsvDialect::resolve()What you will learn
- Choose an output dialect for Excel, Unix, tab, semicolon, or pipe consumers.
- Write UTF-8 or another supported encoding with an appropriate BOM.
- Protect spreadsheet consumers from formula-like text.
Write an Excel-friendly CSV#
Csv::write($rows, 'report.csv', [
'with_header' => true,
'dialect' => 'excel',
'encoding' => 'UTF-8',
'bom' => true,
'injection_policy' => 'escape',
]);Choose a dialect preset#
| Preset | Delimiter | Line ending | BOM |
|---|---|---|---|
excel | Comma | CRLF | Yes |
excel_tab | Tab | CRLF | Yes |
semicolon | Semicolon | CRLF | Yes |
unix | Comma | LF | No |
pipe | Pipe | LF | No |
Prevent formula injection#
Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue