Download the PHP package lukaswerner/php-csv without Composer

On this page you can find all versions of the php package lukaswerner/php-csv. 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 php-csv

php-csv

This library focuses on simplicity and memory efficiency when processing CSV files in PHP.

Features

System Requirements

You need PHP >= 7.1.0 to use php-csv but the latest stable version of PHP is recommended.

Install

Install php-csv using Composer.

Use

You can initialize an object of the main PhpCsv\Csv class by providing a valid \SplFileInfo object to the constructor:

You now have an easy to understand API to process your CSV file. Each processing method will at first rewind the file, so that you don't have any issues with file pointers. If your file does not contain a header row, you must call $csv->setContainsHeader(false);.

Number of lines

You can easily count the number of lines in your csv file by calling $csv->count();. This method will only once examine all lines. On second call it will use its previously set value. To avoid that, you have to create a new object of \PhpCsv\Csv.

Generator return values

The generator, created with $csv->rows() call will now have a return value if not aborted. That means, after iterating through all lines in your CSV file, you can get the line count as the generator return. Do something like this:

Please note, that this will throw an exception, if you use break in your loop. Just like that, the $csv->process() will now return that generator return value or null, if aborted.

Reading header

You can read the header fields by calling $csv->header();. This will return an array of strings with header information. This method will only once examine all lines. On second call it will use its previously set value. To avoid that, you have to create a new object of \PhpCsv\Csv.

Iterating over rows

You can iterate over all rows of your csv file by doing something like this:

The $lineNumber contains the current line number, starting with 1. The header (if existing) is not included. So a file with a header and one line has $lineCount = 1 on that line.

The rows() method returns a PHP Generator and loops can be continued or stopped as you wish.

Processing using callbacks

The php-csv library offers a comfortable process() method to process the CSV file using callbacks. You can do something like this:

Chunking

The callback processing also allows chunking. That means, you have a callback for each row and additionally a callback for each chunk. At first you can set the chunk size with $csv->setChunkSize(500) (default is 1000), then you call the process() method like this:

Please note, that the chunk callback will be called one last time, when you return false from the row callback. That is to be able to flush incomplete chunks.

Contributing

Contributions are welcome and will be fully credited. Please feel free to open issues and ask for repository access.

Changelog

Please see CHANGELOG for more information on what has changed recently.

License

The GNU General Public License v3.0. Please see LICENSE for more information.


All versions of php-csv with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1.0
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 lukaswerner/php-csv contains the following files

Loading the files please wait ....