Skip to content

Instantly share code, notes, and snippets.

@flashvnn
Created April 14, 2021 03:08
Show Gist options
  • Save flashvnn/84e430830d6ee7b45a5fe63c637aeda1 to your computer and use it in GitHub Desktop.
Save flashvnn/84e430830d6ee7b45a5fe63c637aeda1 to your computer and use it in GitHub Desktop.
league csv force enclosure
<?php
$header = ["position" , "team", "played", "goals difference", "points"];
$records = [
[1, "Chelsea", 26, 27, 57],
[2, "Arsenal", 26, 22, 56],
[3, "Manchester City", 25, 41, 54,],
[4, "Liverpool", 26, 34, 53],
[5, "Tottenham", 26, 4, 50],
[6, "Everton", 25, 11, 45],
[7, "Manchester United", 26, 10, 42],
];
$writer = \League\Csv\Writer::createFromPath('./file.csv', 'w');
// Add special enclose.
\League\Csv\EncloseField::addTo($writer, "\tx");
$writer->insertOne($header);
$writer->insertAll($records);
// Get content and replace special enclose.
$content = file_get_contents('./file.csv');
$content = str_replace("\tx", "", $content);
file_put_contents("./file.csv", $content);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment