while (($line = fgets($handle)) !== false) { $data = explode(';', $line); if ($line_count === 0) { $i = 0; foreach ($data as $k) { $column = strtoupper($k); array_push($columns, $column); $header[$column] = $i; $i++; } } else { //print_r($data); $item = array(); foreach ($columns as $k) { $column = strtoupper($k); $item[$column] = $data[$header[$column]]; } print_r($item); } $line_count++; if ($line_count >= $records) { break; } } fclose($handle); } else { // error opening the file. } } select_columns($filename, 3, true);
} print "\n"; } } else { $i = 0; //print_r($data); //print_r($header); foreach ($columns as $k) { $column = strtoupper($k); if ($i > 0) { print ";"; } if ($column[0] === '^') { $field = substr($column, 1); print trim($data[$header[$field]]); } else { print trim($data[$header[$column]]); } $i++; } print "\n"; } $line_count++; } fclose($handle); } else { // error opening the file. } } select_columns($filename, $columns, true);