shuchkin/simplecsv

解析并从CSV文件中检索数据。将数据导出为CSV。

1.0.1 2023-11-14 17:43 UTC

This package is auto-updated.

Last update: 2024-09-14 19:47:55 UTC


README

解析并从CSV文件中检索数据。将数组保存到CSV文件。查看XLSX读取器这里,XLS读取器这里,

Sergey Shuchkin sergey.shuchkin@gmail.com 2015-2023

基本用法

if ( $csv = Shuchkin\SimpleCSV::parse('book.csv') ) {
	print_r( $csv->rows() );
}
Array
(
    [0] => Array
        (
            [0] => ISBN
            [1] => title
            [2] => author
            [3] => publisher
            [4] => ctry
        )

    [1] => Array
        (
            [0] => 618260307
            [1] => The Hobbit
            [2] => J. R. R. Tolkien
            [3] => Houghton Mifflin
            [4] => USA
        )

)

安装

安装此库的推荐方法是通过ComposerComposer新手?

这将安装最新支持的版本

$ composer require shuchkin/simplecsv

或下载类这里

调试

ini_set('error_reporting', E_ALL );
ini_set('display_errors', 1 );

$csv = Shuchkin\SimpleCSV::import('books.csv');
print_r( $csv->rows() );

导出

$items = [
	['ISBN', 'title', 'author'],
	['618260307','The Hobbit','J. R. R. Tolkien']
];
$csv = Shuchkin\SimpleCSV::export( $items );
echo '<pre>' . $csv . '</pre>';
/*
ISBN,title,author
618260307,The Hobbit,J. R. R. Tolkien
*/

历史记录

1.0 (2023-08-27)

  • 现在使用的命名空间:Shuchkin\SimpleCSV
  • 修复了分隔符检测

0.2 (2023-07-27)

  • 修复8x弃用 传递null到参数
  • 添加了静态方法SimpleCSV::parse, SimpleCSV::parseFile, SimpleCSV::parseData

0.1.1 (2021-04-28) 修复7.4弃用 错误
0.1 (2018-12-20) GitHub发布,composer