SplFileObject::setCsvControl
PHP function
Edit on GitHub ✎
(PHP 5 >= 5.2.0, PHP 7, PHP 8)
Set the delimiter, enclosure and escape character for CSV
Description
SplFileObject::setCsvControl(string $separator = ",", string $enclosure = "\"", string $escape = "\\"): void
Sets the delimiter, enclosure and escape character for parsing CSV fields.
Parameters
Escape-parameter
Return Values
Void
Changelog
| Version | Description |
|---|---|
| 7.4.0 | The escape parameter now also accepts an empty string to disable the proprietary escape mechanism. |
Examples
SplFileObject::setCsvControl example
php
<?php
$file = new SplFileObject("data.csv");
$file->setFlags(SplFileObject::READ_CSV);
$file->setCsvControl('|');
foreach ($file as $row) {
list ($fruit, $quantity) = $row;
// Do something with values
}
?>Contents of data.csv
txt
<?php
apples|20
bananas|14
cherries|87
?>See Also
SplFileObject::getCsvControlSplFileObject::fgetcsvSplFileObject::fputcsvfputcsv()fgetcsv()str_getcsv()