1
I’m trying to remove the last comma from an Array but I’m not getting it.
I have a CSV file in which I read and remove an array with a code to be used in a Where of a Query sql. I’m using substr($number_Aut,0,-1) but it’s not working.
Follows the code:
<?
while(! feof($CSVfp)) {
$data = fgetcsv($CSVfp, 1000, ";");
$number_Aut = "'$data[13]','"; //Pego o código desejado no arquivo CSV e adiciono Aspas simples e virgula
if ($data[13] != '') { //Verifico se entre as aspas não tem campos Vazios
echo substr($number_Aut,0,-1); //Elimino a ultima virgula do ARRAY MAS NÃO ESTÁ FUNCIONANDO
}
?>
<tr>
<td align="center"><?php echo date('d/m/Y', strtotime($data[4])); ?></td>
<td align="center"><?php echo $data[11]; ?></td>
<td align="center"><?php echo $data[13]; ?></td>
<td align="center"><?php echo $data[2]; ?></td>
<td align="center"><?php echo $data[9]; ?>/<?php echo $data[10]; ?></td>
<td align="center"><?php echo number_format( $data[8], 2, ',', '.'); ?></td>
<td align="center"><?php echo number_format( $data[17], 2, ',', '.'); ?></td>
</tr>
<?php
}
?>
It would not replace($number_Aut,0,-3); ?
– Don't Panic
($number_Aut,0,-2) takes out all the commas O ($number_Aut,0,-3) takes the ',
– Shaolin Fantastic
if you have the example of this file ?
– novic
question beast, but its CSV is bounded by
,
or;
?– Neuber Oliveira
something else, here Oce adds the comma
$number_Aut = "'$data[13]','";
2 lines after Voce tries to remove the last comma, which just added. It’s not very clear, if you can explain better what you want to do it makes it much easier.– Neuber Oliveira
My file is demilitated by ; In a certain line I remove ; and replace by ' ', to play in the Where of a query so far all right the difficulty is being in removing the last comma
– Shaolin Fantastic