eozzy
eozzy

Reputation: 68680

str_getcsv on a tab-separated file

This works for comma separated file:

array_map('str_getcsv', file('file.csv'));

but this doesn't work for tab separated file:

array_map('str_getcsv("\t")', file('file.TLD'));

Upvotes: 10

Views: 11026

Answers (1)

Rizier123
Rizier123

Reputation: 59681

This should work for you:

array_map(function($v){return str_getcsv($v, "\t");}, file('file.csv'));

Example *.csv file:

a   b   c   d 
1   2   3   4

Output:

Array ( [0] => Array ( [0] => a [1] => b [2] => c [3] => d ) [1] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) )

Upvotes: 23

Related Questions