I there a php function that enables me to read a csv column (COLUMN NOT LINE) into an array or a string ?
thank you in advance.
May this will help. http://www.php.net/manual/de/function.fgetcsv.php Just grab the position of the row for the column you want to have.
$arr=array();
$row = -1;
if (($handle = fopen("test.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
$row++;
for ($c = 0; $c < $num; $c++) {
$arr[$row][$c]= $data[$c];
}
}
fclose($handle);
}
You should give fgetcsv
method a try. It lets you read a file line by line and returns associative array. This function is specially for reading from CSV files.
In any case you will have to read each line even if you will have to process just a column.
http://php.net/manual/en/function.fgetcsv.php
$csv = array_map("str_getcsv", file("data.csv", "r"));
$header = array_shift($csv);
// Seperate the header from data
$col = array_search("Value", $header);
foreach ($csv as $row) {
$array[] = $row[$col];
}