PHP Classes
elePHPant
Icontem

File: example/reader

Recommend this page to a friend!
  Classes of nvb  >  CSV Component for PHP  >  example/reader  >  Download  
File: example/reader
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: CSV Component for PHP
Reader and writer for CSV files
Author: By
Last change:
Date: 3 years ago
Size: 766 bytes
 

Contents

Class file image Download
#!/usr/bin/env php
<?php
/**
 * @author stev leibelt <artodeto@bazzline.net>
 * @since 2015-06-24
 */

require_once __DIR__ . '/../vendor/autoload.php';

$factory    = new \Net\Bazzline\Component\Csv\Reader\ReaderFactory();
$reader     = $factory->create();

try {
    $path = ($argc > 1) ? $argv[1] : __DIR__ . '/file/example.csv';

    if (!file_exists($path)) {
        throw new Exception('invalid file path provided: "' . $path . '"');
    }

    $reader->setPath($path);

    while ($line = $reader()) {
        echo implode("\t", $line) . PHP_EOL;
    }
} catch (Exception $exception) {
    echo 'usage: ' . basename(__FILE__) . ' [<path/to/csv>]' . PHP_EOL;
    echo '----------------' . PHP_EOL;
    echo $exception->getMessage() . PHP_EOL;
    return 1;
}