一个用于处理CSV文件的快速实用库
v1.1.0
2021-05-27 15:46 UTC
Requires
- php: ~7.0
Requires (Dev)
- phpstan/phpstan: ^0.11
- phpunit/phpunit: ^8.3.5
README
这是一个用于在PHP中处理CSV文件的快速实用库。示例请参考 /tests
目录。
安装
composer require daniel-griffiths/csv dev-master
用法
<?php require __DIR__.'/vendor/autoload.php'; use DanielGriffiths\CSV; // Convert a CSV file to a array $rows = CSV::fromFile(__DIR__.'/file.csv'); // Convert an array to a CSV string $csvString = CSV::fromArray([ [ 'animal' => 'Dog', 'name' => 'Patch', ] ])->toString(); // Convert an array to a CSV and download it CSV::fromArray([ [ 'animal' => 'Dog', 'name' => 'Patch', ] ])->download('file.csv'); // Convert an array to a CSV and write it to a file CSV::fromArray([ [ 'animal' => 'Dog', 'name' => 'Patch', ] ])->toFile('file.csv');
测试
./vendor/bin/phpunit