See https://packagist.org/packages/niiyz/csv
-
Create a composer.json defining your dependencies.
{ "require": { "niiyz/csv": "dev-master" } }
-
Require this package in your composer.json and update composer.
composer install
-
test.php
<?php require_once("../vendor/autoload.php"); use Niiyz\Csv\CsvDownload; $list = []; $list[] = ["山田太郎", 12, 165, 50]; $list[] = ["島田ジョン", 11, 175, 67]; $list[] = ["小泉今日子", 48, 155, 45]; $header = ["名前", "年齢", "身長", "体重"]; $csv = new CsvDownload($list, $header); $csv->convertEncoding('UTF-8', 'SJIS-win'); $csv->download('list.csv');
-
list.csv
名前,年齢,身長,体重
山田太郎,12,165,50
島田ジョン,11,175,67
小泉今日子,48,155,45