/* Apply the regex, filling $all_matches with all kinds of data */ preg_match_all($csv_regex, $line, $all_matches); /* $Result will hold the array of fields we'll glean from $all_matches */ $Result = array (); /* Run through each successful match . . . */ for ($i = 0; $i < count($all_matches[0]); $i++) { /* If the 2nd set of capturing parentheses captured, use that directly */ if (strlen($all_matches[2][$i]) > 0) array_push($Result, $all_matches[2][$i]); else { /* It was a quoted value, so take care of an embedded double double-quote before using */ array_push($Result, preg_replace('/""/', '"', $all_matches[1][$i])); } } /* The array $Result is now populated and available for use */ ----------------------------------------------------------------------------- Copyright 1997-2024 Jeffrey Friedl