Problems opening a CSV file with PHP

-1

code that I use to open the file:

$tmp_archivo = "file/catalogo.csv";
$archivo = fopen($tmp_archivo, "r");
$row = 0;
if($archivo){
    while ($datos = fgetcsv($archivo, ",")){
        echo utf8_encode($datos[0])."-".utf8_encode($datos[1])."-".utf8_encode($datos[2])."-".utf8_encode($datos[3])."-".utf8_encode($datos[4])."-".utf8_encode($datos[5])."-".utf8_encode($datos[6])."-".utf8_encode($datos[7])."-"."<br>";
}
}

Content of my CSV file:

100010008,Alambre galvanizado Nº 18,KG,,10001,HAWA,Z205,
100010009,Alambre negro recocido Nº 16,KG,COD.ANT.,10001,HAWA,Z205,GRUPO ART. EXT.
100010010,"Alcayata de acero De 2 1/2""",UN,,10001,HAWA,Z205,

Result that prints to me:

100010008-Alambre galvanizado Nº 18-KG--10001-HAWA-Z205-;;;-
100010009-Alambre negro recocido Nº 16-KG-COD.ANT.-10001-HAWA-Z205-GRUPO ART. EXT.;;;-

Notice: Undefined offset: 1 in /var/www/html/Sis_Pecosa/index.php on line 11

Notice: Undefined offset: 2 in /var/www/html/Sis_Pecosa/index.php on line 11

Notice: Undefined offset: 3 in /var/www/html/Sis_Pecosa/index.php on line 11

Notice: Undefined offset: 4 in /var/www/html/Sis_Pecosa/index.php on line 11

Notice: Undefined offset: 5 in /var/www/html/Sis_Pecosa/index.php on line 11

Notice: Undefined offset: 6 in /var/www/html/Sis_Pecosa/index.php on line 11

Notice: Undefined offset: 7 in /var/www/html/Sis_Pecosa/index.php on line 11
100010010,"Alcayata de acero De 2 1/2""",UN,,10001,HAWA,Z205,;;;--------

The last line keeps it with commas, when they should be replaced by hyphens ... any help? Thank you!

    
asked by Alf 06.07.2018 в 07:02
source

1 answer

0

According to samples, your content is as follows

100010008,Alambre galvanizado Nº 18,KG,,10001,HAWA,Z205,
100010009,Alambre negro recocido Nº 16,KG,COD.ANT.,10001,HAWA,Z205,GRUPO ART. EXT.
100010010,"Alcayata de acero De 2 1/2""",UN,,10001,HAWA,Z205,

So what I can see is that the first two elements the name is between commas (,) but the last element besides being between commas is between double commas (") and it seems that there are some even more. content of the .csv file to

100010008,Alambre galvanizado Nº 18,KG,,10001,HAWA,Z205,
100010009,Alambre negro recocido Nº 16,KG,COD.ANT.,10001,HAWA,Z205,GRUPO ART. EXT.
100010010,Alcayata de acero De 2 1/2,UN,,10001,HAWA,Z205,

Always keep the same style in all fields. Once this is solved, it could be that it works correctly for you

    
answered by 06.07.2018 / 08:09
source