Skip to main content
Version: Fegg 5.x

Csv::field

One value as a CSV field

Description​

public static string Csv::field( mixed $value [, bool $escapeFormulas = true ] )

Returns $value as toString() writes it: converted to text, with a ' before a formula, then quoted when needed (see Writing). Use it to write CSV of your own, a line at a time.

Throws \InvalidArgumentException when $value is an array.

Arguments​

NameData typeDefaultRemarks
$valuemixedString, number, bool, null or date
$escapeFormulasbooltruefalse: no ' before text starting with = + - @

Example​

use Fegg\Tool\Csv;

Csv::field('Hello'); // Hello
Csv::field('a,b'); // "a,b"
Csv::field('say "hi"'); // "say ""hi"""
Csv::field('=1+2'); // '=1+2
Csv::field('-5'); // -5 (numeric text is not escaped)
Csv::field(-5); // -5
Csv::field(null); // (empty)
Csv::field(true); // 1
Csv::field(new \DateTime('2026-11-15 10:00')); // 2026-11-15 10:00:00