alexbrandes / simplecsv
SimpleCsv 是一个简单灵活的 PHP 库,用于读取和操作 CSV 文件。
dev-master / 0.0.1.x-dev
2014-07-09 04:57 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-24 02:06:08 UTC
README
SimpleCsv 是一个简单灵活的库,用于读取和操作 CSV 文件。
使用方法
从文件读取 CSV
$csv = \Reader::create_from_file('./dat.csv');
从字符串读取 CSV
$str = 'header 1, header 2 data 1, data 2'; $csv = \Reader::create_from_string($str);
CSV 到数组
// associative array using first line as headers $csv = \Reader::create_from_file('./dat.csv') ->to_assoc(); // indexed array w/ no headers $csv = \Reader::create_from_file('./dat.csv') ->to_array();
检测分隔符
// automatically detect and set the file delimiter type $csv = \Reader::create_from_file('./dat.csv') ->detect_delimiter(array('|', '%', '$')) ->to_assoc();
安装
使用 Composer 安装 SimpleCsv
包。
{ "require": { "AlexBrandes/SimpleCsv": "*" } }
了解更多关于 Composer 的信息
系统要求
PHP >= 5.3.0
待办事项
- 写入 CSV
- 测试
致谢
- 由 Alex Brandes 编写和维护