Download the PHP package ajgl/csv-rfc without Composer

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

AjglCsvRfc

The AjglCsvRfc component offers a drop in replacement for native PHP CSV related functions to read and/or write RFC4180 compliant CSV files.

Build Status Latest Stable Version Latest Unstable Version Total Downloads Montly Downloads Daily Downloads License SensioLabsInsight

The native PHP implementation contains a Wont fix bug #50686 when you try to write a CSV field which contains the escape char (\ by default), followed by the enclosure char (" by default).

The RFC 4180 states that:

If double-quotes are used to enclose fields, then a double-quote appearing inside a field must be escaped by preceding it with another double quote.

The CSV version of the string "Hello\", World! should be """Hello\"", World!" but it does not work as expected. You can see a detailed explanation at https://3v4l.org/NnHp4

This package provides an alternative implementation to read and write well escaped CSV files for the following functions and methods:

Native Alternative
fgetcsv Ajgl\Csv\Rfc\fgetcsv
fputcsv Ajgl\Csv\Rfc\fputcsv
str_getcsv Ajgl\Csv\Rfc\str_getcsv
SplFileObject::fgetcsv Ajgl\Csv\Rfc\Spl\SplFileObject::fgetcsv
SplFileObject::fputcsv Ajgl\Csv\Rfc\Spl\SplFileObject::fputcsv
SplFileObject::setCsvControl Ajgl\Csv\Rfc\Spl\SplFileObject::setCsvControl

Installation

To install the latest stable version of this component, open a console and execute the following command:

Usage

Alternative functions

The simplest way to use this library is to call the alternative CSV functions:

Alternative clases

If you prefer you can use the alternative implementation for SplFileObject or SplTempFileObject:

Stream filter

Instead of using the alternative functions or classes, you can use the provided stream filter to fix the enclosure escape. You must register the stream filter (if not registered yet) and append it to your stream:

❮ NOTE ❯: The $escape_char in fputcsv MUST be (if allowed) the default one (the backslash \). The $enclosure and $escape parameters in fgetcsv MUST be equals.

Custom enclosure character

By default, the enclosure character of the stream filter is a double-quote ("). If you want to change it, you can provide a custom enclosure character in two different ways.

Via filter params

An array with an enclosure key can be provided when appending the filter to the stream:

Via filter name

If the filter name starts with the special key csv.rfc.write. you can define your custom enclosure character appending it to the filtername:

❮ NOTE ❯: The enclosure character passed via parameters will override the one defined via filter name.

End of line (EOL)

Writing CSV

By default, the PHP CSV implementation uses LF ("\n") as EOL while writing a CSV row. These alternative functions use LF ("\n") by default too.

But, the RFC 4180 states that:

Each record is located on a separate line, delimited by a line break (CRLF).

So, if you want to write RFC4180 compliant CSV, you can override the default EOL using:

Reading CSV

To read the CSV data, this implementation leverages the PHP native capabilities to read files. If you are having any problem with the EOL detection, you should enable the auto_detect_line_endings configuration option as following the PHP doc recomendation.

Integration with league/csv <9.0

The well known league/csv package provide a great object oriented API to work with CSV data, but as long as it leverages the default PHP implementation for CSV, versions prior to 9.0 are affected by the #50686 bug.

You can use this component with league/csv <9.0 to produce RFC 4180 compatible files avoiding this bug.

Writer integration

To integrate this component with the league/csv writer implementation, you can use the Stream Filter API.

❮ NOTE ❯: Do not override the default writer escape character (\).

Known limitations

Reader Integration

To read back the CSV data, you can leverage the standard implementation, but you MUST set the reader escape and enclosure characters to the same value.

License

This component is under the MIT license. See the complete license in the LICENSE file.

Reporting an issue or a feature request

Issues and feature requests are tracked in the Github issue tracker.

Author Information

Developed with ♥ by Antonio J. García Lagar.

If you find this component useful, please add a ★ in the GitHub repository page and/or the Packagist package page.


All versions of csv-rfc with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3 || ^8.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 ajgl/csv-rfc contains the following files

Loading the files please wait ....