Skip to content

Instantly share code, notes, and snippets.

@tcrsavage
Created March 5, 2013 15:59
Show Gist options
  • Save tcrsavage/5091330 to your computer and use it in GitHub Desktop.
Save tcrsavage/5091330 to your computer and use it in GitHub Desktop.
parse csv file to php
function parse() {
if ( ! file_exists( $this->file_path ) || ! is_readable( $this->file_path ) )
return array();
$header = NULL;
$data = array();
if ( ( $handle = fopen( $this->file_path, 'r' ) ) !== FALSE ) {
while ( ( $row = fgetcsv( $handle, 1000, $this->csv_delimiter ) ) !== FALSE ) {
if ( ! $header )
$header = $row;
else
$data[] = array_combine( $header, $row );
}
fclose( $handle );
}
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment