Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

str_getcsv on a tab-separated file

Tags:

php

csv

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'));
like image 836
eozzy Avatar asked Feb 24 '15 08:02

eozzy


1 Answers

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 ) )
like image 144
Rizier123 Avatar answered Oct 07 '22 23:10

Rizier123