fbk / csvmapper
带有字段回调的CSV解析器
0.1.1
2014-12-15 17:15 UTC
Requires
- php: >=5.3.0
- phpoffice/phpexcel: 1.8.*
- symfony/yaml: 2.6.*
Requires (Dev)
- satooshi/php-coveralls: dev-master
This package is not auto-updated.
Last update: 2024-09-23 13:43:52 UTC
README
官方仓库统计
CSVMapper是一个PHP库,用于解析CSV文件。
它允许通过定义一些文件配置和每个(所需)列的属性,将文件映射到数组。
文件设置
CSVMapper需要知道文件的位置和列分隔符。
还可以指定期望的列数,以便在列数不匹配时终止。
$setting = new SettingManager(); $config->set_setting('folder','./tests'); $config->set_setting('filename','myfile.csv'); $config->set_setting('separator',';'); $config->set_setting('columns_allowed',3);
映射
CSVMapper仅提取已定义映射的列。通过映射,可以指定列的位置、应用到的函数以及如何测试值。
$mapping = new MappingManager(); // retrieve column number 1 (counting from 0) and label it as year $mapping->set_mapping("year", array('key'=>1,'fn'=>FALSE,'test'=>FALSE)); // retrieve column number 2 (counting from 0) and label it as temperature, apply to each value the function 'return floatval($input);' $mapping->set_mapping("temperature", array('key'=>2, 'fn'=>create_function('$input','return floatval($input);'),'test'=>FALSE));