Created
May 14, 2012 13:21
-
-
Save kreamweb/2693947 to your computer and use it in GitHub Desktop.
csv to array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function csv2array($content, $delim = ';', $encl = '"', $optional = 1) { | |
if ($content[strlen($content)-1]!="\r" && $content[strlen($content)-1]!="\n") | |
$content .= "\r\n"; | |
$reg = '/(('.$encl.')'.($optional?'?(?(2)':'(').'[^'.$encl.']*'.$encl.'|[^'.$delim.'\r\n]*))('.$delim.'|\r\n)/smi'; | |
preg_match_all($reg, $content, $treffer); | |
$linecount = 0; | |
//= | |
for ($i = 0; $i<count($treffer[3]);$i++) { | |
$liste[$linecount][] = str_replace("\"","",$treffer[1][$i]); | |
if ($treffer[3][$i] != $delim) | |
$linecount++; | |
} | |
unset($linecount); | |
unset($i); | |
unset($reg); | |
unset($content); | |
unset($delim); | |
unset($encl); | |
unset($optional); | |
unset($treffer); | |
return $liste; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment