PHP - Array does not take first value when selecting another line of text

0

I'm having an inconvenience when it comes to getting some data. There are 3 different lines separated by commas (,). The first line reads it to me perfect, now, when it's going to read the second and third line, the first value does not take it as part of the array, it sets it apart. The values are like this:

1,20062018,084821,100.00,01901587620817,inax123-300,PagoFacilPRUEBA,7ad3bf0c1da5cba11e2f98013d505eab8823b2daaeca363ebbfd3286c9e5eb45,c29f4c899fa23962729e69f39272ee2e7bdfa8360b013c2f9ab2f37fd8abfbd3,1
1,20062018,084721,59.99,919000043500160940000007665537000000000057,Marcelo-400,VisaPRUEBA,97f41e27be3d82c08c96ae1b2f66230b37bafbb4b54a958bc1b3f025f4a56112,47ffd120ae5c82746b59194bf8c6dc721b7df9abdda8e31c12e0756f8e0dbc47,2
1,20062018,084521,3500.00,01906409155415,Nicolas-1500,RapiPagoPRUEBA,3b07af83e76a19f6c7020ca8d08ac940ef71e7e34851596a10110a802ac7033d,37a96629e715d7fc7e2d83e2af1c8b41310b6524a9262c4940b3edf6c41bfe8b,3
3,20062018,084921,3659.99,0.00,3,d5a003c5c3337638a2f4baca970dd1f89614b4663ec4ee0d56d33e4e4f96c01b

The last value of the line identifies the number of the line, but the array does not take it and shows me the data like this:

Array
(
    [0] => 1
    [1] => 20062018
    [2] => 084821
    [3] => 100.00
    [4] => 01902226247728
    [5] => asdasdsa-300
    [6] => PagoFacilPRUEBA
    [7] => ea5d299b037d2455fb3bc0af0d544a0810c53240e395b001235415479469475e
    [8] => 056577d6c33d167b991fa4963fec77aec0d7c5a24a9ed69317cd463615c976e8
    [9] => 1
1
    [10] => 20062018
    [11] => 084621
    [12] => 59.99
    [13] => 919000043500160940000004282022900000000028
    [14] => Marcelo-400
    [15] => VisaPRUEBA
    [16] => 729dd1a5a6e92f296018b5168c83ff6292cf53f8ebe6002cba9ddf00ee950278
    [17] => b21f41174e681f4ddb5393789cf9dd74b98f9ae52b79890b009e69eab11759a9
    [18] => 2
1
    [19] => 20062018
    [20] => 084721
    [21] => 3500.00
    [22] => 01909419702422
    [23] => Nicolas-1500
    [24] => RapiPagoPRUEBA
    [25] => 9d8d0073837401eb26a04f954edcc22b776ea81dc9c802a300d5390a8e185ca1
    [26] => 19002789901770eac68779a4aeaae383c40840f8974754c0fc44ea46f580708c
    [27] => 3
3
    [28] => 20062018
    [29] => 084921
    [30] => 3659.99
    [31] => 0.00
    [32] => 3
    [33] => d5a003c5c3337638a2f4baca970dd1f89614b4663ec4ee0d56d33e4e4f96c01b
)

As you will see, there are 10 values for each line. but he does not read me the first one after reading the first line.

The code is as follows:

$lines = explode(PHP_EOL, $VALORES);
$array = array();

foreach ($lines as $line) {
    $array = str_getcsv($line);


}
    
asked by Ignacio Copparoni 20.06.2018 в 13:56
source

1 answer

1

The result you have seems to indicate that the problem is that the array lines has only one element, that is, the separation you have between the lines is not being recognized using PHP_EOL , so it puts you all in one array in the each element is the separation by "," which is the default delimiter of the function str_getcsv ( ) .

If it were recognized, the expected result would be an array with number of elements equal to the number of lines and each formed by an array of 10 elements. You can see it if you execute this example:

$text = "1,20062018,084821,100.00,01901587620817,inax123-300,PagoFacilPRUEBA,7ad3bf0c1da5cba11e2f98013d505eab8823b2daaeca363ebbfd3286c9e5eb45,c29f4c899fa23962729e69f39272ee2e7bdfa8360b013c2f9ab2f37fd8abfbd3,1
1,20062018,084721,59.99,919000043500160940000007665537000000000057,Marcelo-400,VisaPRUEBA,97f41e27be3d82c08c96ae1b2f66230b37bafbb4b54a958bc1b3f025f4a56112,47ffd120ae5c82746b59194bf8c6dc721b7df9abdda8e31c12e0756f8e0dbc47,2
1,20062018,084521,3500.00,01906409155415,Nicolas-1500,RapiPagoPRUEBA,3b07af83e76a19f6c7020ca8d08ac940ef71e7e34851596a10110a802ac7033d,37a96629e715d7fc7e2d83e2af1c8b41310b6524a9262c4940b3edf6c41bfe8b,3";
$lines = explode(PHP_EOL, $text);
var_dump($lines);
$array = array();
foreach ($lines as $line) {
    $array[] = str_getcsv($line);   

}
var_dump($array);

Check the type of separation between the lines so that the% co_of initial% works correctly.

    
answered by 20.06.2018 / 15:03
source