I have a csv file where fields are separated by semicolons. Inside each field we can have comma (decimal separator for numbers in italy is comma). a sample data is:
15/01/2021;15/01/2021;ADDEBITO SDD;PAGAMENTO NEXI 8000640000030620818186 NEXI S.P.A. CORSO SEMP - ADDE BITO SPESE CARTA DI CREDITO ESTRATTO CONTO DEL : 31/ 12/2020 - UNCRITMMXXX IT500040000004107060966;1.501,2;;Uscita;
I explode this line by semicolon and then build a table row out of it:
while (($line = fgetcsv($f)) !== false) {
$row = $line[0];
$cells = explode(";",$row);
echo "<tr>";
foreach ($cells as $cell) {
echo "<td>";
echo htmlspecialchars($cell);
echo "</td>";
$cur_col_num+=1;
}
echo "</tr>\n";
The issue I have is that the string "1.501,2" is echoed as 1.501 loosing the decimals. If the source is "1501.2" this is echoed correctly as "1501.2". How do I keep the decimal if the separator is a comma? I have no control over the content of the csv that is coming from different sources and so I need to handle both situations.
EDIT: after some more tests I realized that actually for any line containg the comma it stops processing the line after the comma (ignoring the following fields). So in the example I never see "Uscita" in its table cell
EDIT 2: this is the output of my code on the browser for this specific line