ecommit / csv-table-generator
使用PHP数组创建CSV文件。
v1.2.1
2024-06-21 18:12 UTC
Requires
- php: ^7.4|^8.0
- symfony/options-resolver: ^5.4|^6.4|^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^9.0
- vimeo/psalm: ^5
README
使用PHP数组创建CSV文件。
安装
要使用Composer安装csv-table-generator,只需运行
$ composer require ecommit/csv-table-generator
用法
use Ecommit\CsvTableGenerator\Csv; $csv = new Csv('/home/test', 'myfilename', array( 'header' => array( 'Column A', 'Column B', ), )); $csv->write(array('Hello', 'world')); //Add line $csv->write(array('Test1', 'Test2')); //Add line $csv->close();
/home/test/myfilename.csv已生成
"Column A","Column B"
Hello,world
Test1,Test2
构造函数参数
- String $pathDir : 生成CSV文件的路径文件夹(必需)
- String $filename : 文件名(不含路径文件夹和扩展名)(必需)
- Array $options : 选项。见下文
可用选项
- header (数组) : 标题数组。如果为空,则没有标题。默认:array()
- max_lines (null | int) : 每个CSV文件的最大行数。如果行数 > max_lines,则生成多个文件。默认:null
- delimiter (字符串) : CSV分隔符。默认:,
- enclosure (字符串) : CSV封装符。默认:"
- eol (字符串 - Csv::EOL_ 常量) : EOF(文件结束)字符。见 Csv::EOL_ 常量。默认:Csv::EOL_LF。如果使用 Csv::EOL_CRLF 且PHP ≤ 8.1,则需要 unix2dos 程序
- escape : CSV转义符。默认:\
- unix2dos_path (字符串) : Unix2dos路径。仅当eol=Csv::EOL_CRLF且PHP ≤ 8.1时使用。默认:/usr/bin/unix2dos
- add_utf8_bom (布尔值) : 添加或删除UTF8 bom。默认:false
许可证
此库在MIT许可证下。在LICENSE文件中查看完整许可证。