一个用于处理CSV文件的快速实用库

v1.1.0 2021-05-27 15:46 UTC

This package is auto-updated.

Last update: 2024-09-25 14:59:40 UTC


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