Download the PHP package tonyfarney/csv-writer without Composer

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

CSVWriter

Ease to use CSV Writer for PHP 7+

Instalation

In your project root, run the following composer command:

$ composer require tonyfarney/csv-writer

In order to use the encoding conversion implemented, you need to install the mbstring extension or a equivalent polyfill such as symfony/polyfill-mbstring.

Writing CSV File From an Array of Data

CSVWriter generates CSV file from array of data containing the lines and columns. Examples:

<?php
require __DIR__.'/vendor/autoload.php';

use \CSVWriter\CSVWriter;

$lines = [
    ['name', 'role', 'age'],
    ['Tony Farney', 'Developer', 30],
    ['The Coffe Guy', 'Intern', 18],
    ['Someone Else', 'Developer', 26],
];

$writer = new CSVWriter();

// Add lines to the buffer
foreach ($lines as $line) {
    $writer->addLine($line);
}
// Saves the buffer to a file
$writer->save('/tmp/file.csv');

// Gets de generated CSV from buffer
$csv = $writer->getCSV();
echo $csv."\n\n";

// Changes the configuration and get new CSV from buffer
$newCsv = $writer->setEnclosureRule(CSVWriter::ENCLOSURE_NONE)
    ->setNewLineDelimiter("\r\n")
    ->setColumnDelimiter(';')
    ->setEncodings('UTF-8', 'ISO-8859-1') // Converts from UTF-8 to ISO-8859-1
    ->getCSV()
;
echo $newCsv;

echo $csv; output:

"name","role","age"
"Tony Farney","Developer","30"
"The Coffe Guy","Intern","18"
"Someone Else","Developer","26"

echo $newCsv; output:

name;role;age
Tony Farney;Developer;30
The Coffe Guy;Intern;18
Someone Else;Developer;26

Tips

When writing to a file, it's possible save memory limiting the buffer size:

// Causes writing to file and clearing the buffer when buffer reaches 1000 lines
$writer->setMaxLinesBuffer(1000);

It's possible reset configuration and clear the buffer at any time

// Resets all configurations to it's default value
$writer->resetConfig();

// Clears the buffer 
$writer->clearBuffer();

// Resets config and clears the buffer
$writer->reset();

Contributions/Support

You are welcome to contribute with improvement, bug fixes, new ideas, etc. Any doubt/problem, please contact me by email: [email protected]. I'll be glad to help you ;)


All versions of csv-writer with dependencies

PHP Build Version
Package Version
Requires php Version ^7.0|^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 tonyfarney/csv-writer contains the following files

Loading the files please wait ...