krzysztof krzysztof - 1 year ago 152
PHP Question

php CSV headers for columns

I am the beginer in programing,
could anyone help me , how can I write in php headers of the columns for generated CSV file . Like I want to set header ( name, surname , address)
enter image description here

Answer Source

You could read the .csv file into an array with file(), then create a new array, assigning the headers as the first entry, followed by writing all lines from the csv file to the new array. Finally, save your new CSV.

$oldcsv = file('sample.csv');
$csv = array();
$csv[] = "name,surname,address";
foreach($oldcsv as $v){
   $csv[] = $v;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download