I have a csv file with data row 1 is header like this
id fname lname email date code pid
each row then has data below each field name
3232456454 mike strong [email protected] 11/8/11 0:00 AU 2540
and when i see this csv using text editor, i see it as below.
3232456454,mike,strong,[email protected],11/8/11 0:00,AU,2540
87876548788,bob,cool,[email protected],11/8/11 0:00,RY,2148
23498765,nike,tick,[email protected],11/8/11 0:00,TE,5240
Now i want to read the file using php and i want the data to be exactly same format as text file. I will use this data for other purpose as it is. I don't want to split at commas so i cannot use fgetcsv. I tried by just opening it using php file() but when i loop it, i don't see the proper data. Can some one please throw some suggestions?
if I do this way, it prints in the array with each element taking one value and I don't want this..
$csv = array();
$lines = file('sample.csv', FILE_IGNORE_NEW_LINES);
foreach ($lines as $key => $value)
{
$csv[$key] = str_getcsv($value);
}
print_r($csv)
I tried using parsecsv library from google code but this is not really necessary as i want the data line by line.
I need to ignore the first line(header) in the output.
If i can get the output like this, this will solve my issues
Array
(
[id,fname,lname,email,,data,code,pid] => 3232456454,mike,strong,[email protected],11/8/11 0:00,AU,2540
)
Array
(
[id,fname,lname,email,,data,code,pid] => 87876548788,bob,cool,[email protected],11/8/11 0:00,RY,2148
)
regards