A quick utility library for working with CSV's

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

This package is auto-updated.

Last update: 2024-04-06 05:08:44 UTC


README

A quick utility library for working with CSV's in PHP. See /tests for examples.

Installation

composer require daniel-griffiths/csv dev-master

Usage

<?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');

Tests

./vendor/bin/phpunit