• Stars
    star
    134
  • Rank 270,967 (Top 6 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 12 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CSV reader/writer

Keboola CSV reader/writer

Latest Stable Version License Total Downloads

The library provides a simple reader and writer for CSV files according to RFC4180. The library is licensed under the MIT license. The library provides classes CsvReader and CsvWriter for reading and writing CSV files. The classes are designed to be immutable and minimalistic.

Usage

Read CSV

$csvFile = new Keboola\Csv\CsvReader(__DIR__ . '/_data/test-input.csv');
foreach($csvFile as $row) {
	var_dump($row);
}

Skip lines

Skip the first line:

$csvFile = new \Keboola\Csv\CsvFile(
    $fileName,
    CsvFile::DEFAULT_DELIMITER,
    CsvFile::DEFAULT_ENCLOSURE,
    CsvFile::DEFAULT_ESCAPED_BY,
    1
)
foreach($csvFile as $row) {
	var_dump($row);
}

Write CSV

$csvFile = new Keboola\Csv\CsvWriter(__DIR__ . '/_data/test-output.csv');
$rows = [
	[
		'col1', 'col2',
	],
	[
		'first column', 'second column',
	],
];

foreach ($rows as $row) {
	$csvFile->writeRow($row);
}

Append to CSV

$fileName = __DIR__ . '/_data/test-output.csv';
$file = fopen($fileName, 'a');
$csvFile = new Keboola\Csv\CsvWriter($file);
$rows = [
	[
		'col1', 'col2',
	],
	[
		'first column', 'second column',
	],
];

foreach ($rows as $row) {
	$csvFile->writeRow($row);
}
fclose($file);

Write CSV With Windows new-lines

$csvFile = new Keboola\Csv\CsvWriter(
    'test-output.csv',
    CsvWriter::DEFAULT_DELIMITER,
    CsvWriter::DEFAULT_ENCLOSURE,
    "\r\n"
)
$rows = [
	[
		'col1', 'col2',
	],
	[
		'first column', 'second column',
	],
];

foreach ($rows as $row) {
	$csvFile->writeRow($row);
}

Installation

The library is available as composer package. To start using this library in your project follow these steps:

Install package:

composer require keboola/csv

Add autoloader in your bootstrap script:

require 'vendor/autoload.php';

Read more in Composer documentation

Development

Clone this repository and init the workspace with following command:

git clone https://github.com/keboola/php-csv.git
cd php-csv
docker-compose build
docker-compose run --rm dev composer install --no-scripts

Run the test suite using this command:

docker-compose run --rm dev composer tests

License

MIT licensed, see LICENSE file.

More Repositories

1

ex-facebook-graph-api

facebook graph api extractor(insights and fb-ads intended)
Clojure
37
star
2

php-encryption

Mcrypt wrapper - AES encryption support
12
star
3

generic-extractor

Generic Extractor
PHP
11
star
4

storage-api-php-client

Storage API Client
PHP
10
star
5

openrefine-php-client

OpenRefine PHP Client
PHP
10
star
6

adwords-extractor

PHP
8
star
7

python-component

General library for Python applications running in Keboola Connection environment
Python
7
star
8

ssh-tunnel

Simple PHP class for opening SSH tunnels
PHP
7
star
9

serverless-papertrail-logging

JavaScript
7
star
10

keboola-as-code

Keboola Connection project as definition files.
Go
7
star
11

component-generator

Tool for creating Keboola Connection components
PHP
6
star
12

php-jsonparser

Json to CSV files parser & analyzer
PHP
6
star
13

sapi-python-client

Keboola Connection Storage API client
Python
6
star
14

google-analytics-extractor

Google Analytics Extractor
PHP
6
star
15

angular-kb

Angular extensions library
CoffeeScript
5
star
16

indigo-ui

Indigo UI library, its CSS and React components. Also Styleguide app showing usages of this library.
JavaScript
5
star
17

connection-docs

Keboola Connection Documentation
SCSS
5
star
18

php-db-import

PHP
4
star
19

middy-error-logger

Error logger middleware for Middy
JavaScript
4
star
20

db-extractor-db2-deprecated

IBM DB2 extractor
PHP
4
star
21

keboola-as-code-templates

Templates repository for Keboola as Code CLI client
Jsonnet
4
star
22

python-json-to-csv

Python
3
star
23

storage-backend

Storage backend related tools monorepo
PHP
3
star
24

docker-custom-python

Base image for Python components
Dockerfile
3
star
25

go-client

Go clients for Keboola APIs.
Go
3
star
26

developers-docs

Keboola Connection Developers Documentation
SCSS
3
star
27

phpstorm-shared-configuration

3
star
28

papertrail-json-parser-chrome-extension

Chrome Web Store
JavaScript
3
star
29

serverless-default-error-responses

JavaScript
3
star
30

storage-api-cli

Keboola Storage API Command Line Interface
PHP
3
star
31

keboola_streamlit

A Python library for working with Kbc SAPI Client.
Python
3
star
32

dbt-transformation

PHP
2
star
33

python-docker-application

General library for python applications running in KBC docker environment
Python
2
star
34

php-storage-driver-bigquery

PHP
2
star
35

google-drive-extractor-config-rows

Extract data from Goole Drive files and spreadsheets
PHP
2
star
36

php-csvmap

Convert JSONs to CSVs using simple mapping.
PHP
2
star
37

middy-event-validator

Event validation middleware for Middy
JavaScript
2
star
38

keboola-streamlit-cookiecutter

Cookiecutter Keboola Streamlit App
Python
2
star
39

flow-builder

TypeScript
2
star
40

http-extractor

Extract data from publicly accessible URL
PHP
2
star
41

input-mapping-original

Input mapping library for Docker Runner
PHP
2
star
42

shopify-tmlblock

2
star
43

datadir-tests

PHP
2
star
44

gooddata-writer-v3

GoodData Writer v3 for Keboola Connection
PHP
2
star
45

kbc-ui-templates

JavaScript
2
star
46

platform-libraries

PHP
2
star
47

no-code-dbt-transformation

PHP
2
star
48

app-scaffold

Scaffold application can setup project using list of oprerations.
PHP
2
star
49

symfony-console-nested-formatter-helper

Nested array formatter helper for Symfony Console
PHP
2
star
50

serverless-request-handler

JavaScript
2
star
51

tde-exporter

export storage api tables to TDE
Python
2
star
52

app-snowflake-dwh-manager

PHP
2
star
53

provisioning-fake-sandbox

PHP
1
star
54

public-project-guidelines

1
star
55

db-writer-mysql

PHP
1
star
56

snowflake-transformation

PHP
1
star
57

snowflake-happy-hours

Component for changing Snowflake warehouse size and parameters.
PHP
1
star
58

docker-demo

1
star
59

debug-log-uploader

Simple package for uploading logs to AWS S3, Azure Blob Storage or local filesystem.
PHP
1
star
60

tmp-streamlit-ai

Python
1
star
61

input-mapping

[READ-ONLY] Input mapping library for Docker Runner
PHP
1
star
62

looker-api

PHP
1
star
63

sklik-extractor

PHP
1
star
64

codemirror-mode-sfsql

JavaScript
1
star
65

db-extractor-firebird

PHP
1
star
66

php-storage-driver-common

[READ-ONLY] - see https://github.com/keboola/storage-backend
PHP
1
star
67

php-db-import-export

[READ-ONLY] - see https://github.com/keboola/storage-backend
PHP
1
star
68

ex-generic-mock-server

Mock API server for Generic Extractor documentation examples
PHP
1
star
69

db-proxy-service

TypeScript
1
star
70

legacy-php-encryption

Legacy Encryption library
PHP
1
star
71

php-filter

Part of Generic Extractor
PHP
1
star
72

token-sniffer

1
star
73

php-storage-driver-teradata

PHP
1
star
74

php-datatypes

[READ-ONLY] - see https://github.com/keboola/storage-backend
PHP
1
star
75

aws-reservations

Pair AWS EC2 instances with reservations
PHP
1
star
76

ex-snowflake-query-history

PHP
1
star
77

fakturoid-writer

Custom Docker application for pushing invoicing data to Fakturoid.
PHP
1
star
78

logging-bundle

[READ-ONLY]
PHP
1
star
79

geocoding-augmentation

Geocoding service for Storage API
PHP
1
star
80

serverless-demo-app

JavaScript
1
star
81

docker-jupyter

Shell
1
star
82

processor-transpose

Transpose table data
PHP
1
star
83

storage-api-js-client

Javascript client for Keboola Storage API
JavaScript
1
star
84

storage-api-dotnet-client

API http://docs.keboola.apiary.io/ wrapper .NET library (DEPRECATED)
C#
1
star
85

azure-key-vault-php-client

PHP
1
star
86

gmail-extractor

Gmail Extractor - Docker application for extracting messages from Gmail.
PHP
1
star
87

output-mapping-original

Output mapping library for Docker Runner
PHP
1
star
88

docker-bundle

Docker Runner component
PHP
1
star
89

processor-split-table

Go
1
star
90

python-transformation-v2

Python
1
star
91

elastic-writer

Elasticsearch Writer
PHP
1
star
92

db-extractor-db2-bata

Custom DB2 extractor with AS400 drivers from and for Bata.
PHP
1
star
93

ex-email-attachments

Keboola Email attachments extractor
PHP
1
star
94

processor-iconv

PHP
1
star
95

db-extractor-mssql

PHP
1
star
96

db-extractor-pgsql

Postgres DB Extractor
PHP
1
star
97

docker-rstudio

Docker image with RStudio server based on Keboola R Docker.
Shell
1
star
98

codedeploy-monitor

Simple CodeDeploy SDK wrapper
PHP
1
star
99

php-codebuilder

Part of Generic Extractor
PHP
1
star
100

handbook

Keboola Handbook
1
star