Login   Register  
PHP Classes

File: README.md

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of P Guardiario  >  PG CSV  >  README.md  >  Download  
File: README.md
Role: Documentation
Content type: text/plain
Description: Documentation
Class: PG CSV
Parse and write data from arrays into CSV files
Author: By
Last change:
Date: 1 year ago
Size: 778 bytes


Class file image Download

A 'pretty good' CSV library for Php

### Writing

$fields = array('name', 'phone', 'address');

$csv = new CSV('output.csv', $fields);

$person = array(
  'name' => 'Jow Brown',
  'phone' => '123 222-0123',
  'address' => '666 Buckingham Palace'


By default, CSV saves data with a utf-8 BOM to make it Excel-friendly. You can change that though.

### Reading

$data = CSV::read('input.csv');

CSV expects the first row to be headers, but you can change that. You can also change the delimiter.

### Iterating

foreach(CSV::iterate('input.csv') as $row){
  echo $row['name'] . "\n";

Iterating this way means the whole file does not need to be in memory.