Download the PHP package juanparati/csvreader without Composer

On this page you can find all versions of the php package juanparati/csvreader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package csvreader

CSVReader

About

CSVReader is lightweight and fast CSV reader library for PHP 7.x that is suitable for large size files.

CSVReader was developed for business and e-commerce environments where large CSV files with possible corrupted data can be ingested.

Features

Notes

Usage

Custom field map (For CSV with header)

    $csv = new \Juanparati\CSVReader\CSVReader(
        'file.csv',     // File path 
        ';',            // Column delimiter
        '"',            // Text enclosure
        'UTF-8',        // Charset
        ',',            // Decimal separator
        '\\'            // Escape character
    );

    // Define a custom map
    $csv->setMapField([
        'name' => ['column' => 'Firstname'],
        'price' => ['column' => 'Retailprice'],
    ],
    0   // Define where the head line. Default: 0 (first line)
    );

    // Extract rows sequentially
    while ($row = $csv->readCSVLine())
    {
        echo 'Name: ' . $row['name'];
        echo 'Price: ' . $row['price'];             
    }

Custom field map (For CSV without header)

    $csv = new \Juanparati\CSVReader\CSVReader(
        'file.csv',     // File path 
        ';'             // Column delimiter
    );

    // Define a custom map
    $csv->setMapField([
        'name' => ['column' => 0],
        'price' => ['column' => 3],
    ]);

    // Extract rows sequentially
    while ($row = $csv->readLine())
    {
        echo 'Name: ' . $row['name'];
        echo 'Price: ' . $row['price'];             
    }

Automatic field map

    $csv = new \Juanparati\CSVReader\CSVReader(
        'file.csv',     // File path 
        ';'             // Column delimiter
    );

    // Define a custom map
    $csv->setAutomaticMapField();

    // Extract rows sequentially
    while ($row = $csv->readCSVLine())
    {
        echo 'Firstname: ' . $row['Firstname'];
        echo 'Retailprice: ' . $row['Retailprice'];             
    }

Column separators

Separators are set as string or constant representation.

Separators Constant
; \Juanparati\CSVReader\CSVReader::DELIMITER_SEMICOLON
, \Juanparati\CSVReader\CSVReader::DELIMITER_COMMA
\Juanparati\CSVReader\CSVReader::DELIMITER_PIPE
\t \Juanparati\CSVReader\CSVReader::DELIMITER_TAB
^ \Juanparati\CSVReader\CSVReader::DELIMITER_CARET

It is possible to use all kind of separators so it is not limited to the enumerated ones.

String enclosures

Enclosure Constant
~ \Juanparati\CSVReader\CSVReader::ENCLOSURE_TILDES
" \Juanparati\CSVReader\CSVReader::ENCLOSURE_QUOTES
No enclosure \Juanparati\CSVReader\CSVReader::ENCLOSURE_NONE

Enclosure node is used when strings in CSV are not enclosed by any kind of character.

Decimal separators

Decimal separator Constant
. \Juanparati\CSVReader\CSVReader::DECIMAL_SEP_POINT
, \Juanparati\CSVReader\CSVReader::DECIMAL_SEP_COMMA
' \Juanparati\CSVReader\CSVReader::DECIMAL_SEP_APOSTROPHE
\Juanparati\CSVReader\CSVReader::DECIMAL_SEP_APOSTROPHE_9995

Column casting

It is possible to cast columns using the cast attribute.

      // Define a custom map
      $csv->setMapField([                
        'price' => ['column' => 'Retailprice', 'cast' => 'float'],
      ]);

Available casts are:

Remove characters from column

Sometimes is required to remove certain characters on a specific column.

      // Define a custom map
      $csv->setMapField([                
        'price' => ['column' => 'Retailprice', 'cast' => 'float', 'remove' => ['EUR', '€'] 
      ]);

Replace characters from column

      // Replace "Mr." by "Señor"
      $csv->setMapField([                
        'name' => ['column' => 'Firstname', 'replace' => ['Mr.' => 'Señor'] 
      ]);

Exclude flag

Sometimes is convenient to flag rows according to the column data.

      // Exclude all names that equal to John
      $csv->setMapField([                
        'name' => ['column' => 'Firstname', 'exclude' => ['John'] 
      ]);

In this every time that column "name" has the word "John", the virtual column "exclude" will containe the value "true" (boolean).

The exclude parameter accepts regular expressions.

Apply stream filters

     $csv = new \Juanparati\CSVReader\CSVReader('file.csv');
     $csv->applyStreamFilter('zlib.deflate')

File information

It is possible to get current pointer position in bytes calling to the "tellPosition" method. In order to obtain the file stat a call to the "info" method will return the file stat (See http://php.net/manual/en/function.fstat.php).

    $csv = new \Juanparati\CSVReader\CSVReader('file.csv');
    echo 'Current byte position ' . $csv->tellPosition() . ' of ' . $csv->info()['size'];

Backers


All versions of csvreader with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0.1
ext-mbstring Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package juanparati/csvreader contains the following files

Loading the files please wait ....