I'm currently importing CSV data and need to get it all nice and arrayed out.
Smaller Example Data is as follows.
"Name","Address"
"John Doe","5111 Fury Rd
Santa Cruz"
"Jane Doe","321 Tess St Texas"
"Josh Doe","653 1st St
Orlando Florida
United States"
As you can see we need to split on line breaks outside of quotes as str_getcsv isn't multi-line.
I had originally used this expression.
$lines = preg_split('/[\r\n]{1,2}(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/',$data);
However preg_split crapped the bed when it was over XXXX amount of characters in the string.
So resorting to preg_match_all currently but need issues with the regex selector.
preg_match_all('/^(.*?)[\r\n]{1,2}(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/', $data, $matches);
Currently that matches only the first instance.
Array(
[0] => Array ( [0] => "Name","Address")
[1] => Array ( [0] => "Name","Address")
)
Any clue to get it to return all the data in an array?