Skip to content

Instantly share code, notes, and snippets.

@benbalter
Created July 24, 2012 22:28

Revisions

  1. benbalter revised this gist Jul 25, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions parse-csv.php
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,8 @@
    foreach ( str_getcsv( $line ) as $key => $field )
    $row[ $headers[ $key ] ] = $field;

    $row = array_filter( $row );

    $data[] = $row;

    }
  2. benbalter created this gist Jul 24, 2012.
    15 changes: 15 additions & 0 deletions parse-csv.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    <?php

    $lines = explode( "\n", file_get_contents( 'input.csv' ) );
    $headers = str_getcsv( array_shift( $lines ) );
    $data = array();
    foreach ( $lines as $line ) {

    $row = array();

    foreach ( str_getcsv( $line ) as $key => $field )
    $row[ $headers[ $key ] ] = $field;

    $data[] = $row;

    }