$csvFile = [];
$firstRow = ['#','Freq','Mode','Shift','Offset','TX Freq','Enc/Dec','Tone','Code','Show','Name','Power','Scan','Clk','Step','Scan2','Scan3','Scan4','Scan5','Scan6','Description','Bank1','Bank2','Bank3','Bank4','Bank5','Bank6','Bank7','Bank8','Bank9','Bank10','Bank11','Bank12','Bank13','Bank14','Bank15','Bank16','Bank17','Bank18','Bank19','Bank20','Bank21','Bank22','Bank23','Bank24','PRFRQ','SMSQL','RXATT','BELL','Masked','Internet','DCSinv'];
array_push($csvFile, $firstRow);
while($row = mysqli_fetch_array($result)) {
$element = [count($csvFile), $RX, $modulation, $offsetDirection, $offsetFrequency, '', $toneMode, $CTCSS, '023', '', $row['Repeater'].'-'.$row['Sign'], 'HIGH', 'Off', 'OFF', "12.5 K", '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '1600HZ', 'OFF', 'OFF', 'OFF', 'NO', 'OFF', 'RN-TN'];
array_push($csvFile, $element);
}
function array_to_csv_download($array, $filename = "FTBVX8DE.csv", $delimiter=";") {
$f = fopen('php://memory', 'w');
foreach ($array as $line) {
fputcsv($f, $line, $delimiter);
}
fseek($f, 0);
header('Content-Type: application/csv');
header('Content-Disposition: attachment; filename="'.$filename.'";');
fpassthru($f);
}
array_to_csv_download($csvFile);
Hi guys, I do need your help. Above is a snippet of code that creates a CSV file to import data in a specific software for ham radio operators. Apparently if I open the file in Excel, the output looks correctly, with corresponding fields/values in columns.
But when I try to import data in the software, an error occurs. Opening the CSV file in Notepad I noticed that my data were shown straight into a single line: wrong formatting without a pseudo carriage return
Instead, the formatting for a succesfull import should be:
correct formatting must be exactly like this
Now, I tried several ways to accomplish this task searching in StackOverflow, for instance inserting PHP_EOL, but unsuccessfully.
Any help/suggestion, please? Thank you so much!