定制 chrismou/php-eol-csv 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

chrismou/php-eol-csv

Composer 安装命令:

composer require chrismou/php-eol-csv

包简介

A class for creating CSV files, allowing you to set a custom end-of-line character

README 文档

README

When I wrote this it did exactly what I needed it to do, but with the number of great 3rd party packages available now it's not really needed anymore. If you want full control of your CSVs, check out the excellent phpleague/csv

PHP Custom end-of-line CSV class

Travis Build Status Test Coverage Code Climate Buy me a beer

About

This class provides the flexibility of creating CSV files in PHP with a custom end-of-line character.

PHP's fputcsv function allows you to specify a field delimiter, but strangely doesn't let you set the EOL character - which, when it insists on \n, isn't always helpful when the files are destined for people to view/edit on a Windows based systems.

Install

To install via Composer:

composer require chrismou/php-eol-csv

Usage

Instantiate the class:

$csv = new \Chrismou\PhpEolCsv\Csv;

Open a CSV file for editing:

$csv->open($fileName, $savePath, $eol, $fileExtension, $delimiter, $enclosure);
  • $fileName (required) - the filename to use. Don't include the file extension, this can be set seperately.
  • $savePath - The path to save the file. Leaving this blank will save directly to the output buffer for a direct download.
  • $eol - The EOL character/string to use. Defaults to \n.
  • $fileExtension - The file extension to use. Defaults to csv.
  • $delimiter - The character/string to use as a separator between fields. Defaults to ,.
  • enclosure - The character to use to enclose multi-word strings, or strings that include the delimiter character. Defaults to ".

Write a row to the CSV:

$csv->write(array("Field1", "Field2", "Field3"));

Finish editing and close the file:

$csv->close();

Supported versions

PHP 5.3 upwards, including HHVM.

Tests

To run the unit test suite:

curl -s https://getcomposer.org/installer | php
php composer.phar install
./vendor/bin/phpunit

A DUnit config file is also included, allowing you to easily run tests on all supported PHP versions.

First, you need to have docker installed. This is fairly simple on Linux - on OSX and Windows, take a look at docker machine.

Assuming you have composer setup (see above), run the tests with the following command:

./vendor/bin/dunit

License

Released under the MIT License. See LICENSE.md.

统计信息

  • 总下载量: 110
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-11-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固