Read data over file . csv

Asked

Viewed 74 times

0

I have a PHP system reading data from a csv file. It displays the barcode number where I will relate to the database for update according to the file sent in the system. Example:

User sends CSV file with data: 'Bars' => 7896603803918, 'Qtd' => '1'

When reading the file I receive the value of bars: "7,8966E+12" which is not the same displayed in the correct value.

When opening the file. csv in excel, I actually find the text being displayed as "7,8966E+12", but when I click to check the value of the function, I get the correct number of 7896603803918.

My problem boils down to: The file . csv sends me an exponential number that does not represent the real number, making it impossible to import. What would be the right solution so that I could remove these values correctly from the . csv file or if it is a problem that everyone faces.

Code currently being used:

<?php
$csv = str_getcsv(file_get_contents('data.csv', 'r'), ';');
var_dump($csv);
  • The problem is that Excel or any other program that is using to generate the spreadsheet is recognizing the barcode as number and formatting, thus generating the wrong forum csv. You need to set the column as text in the editor

1 answer

0

You are probably trying to pass bars to int, the highest value for int32 is 2 32-32, try passing the value to string or try using a 64-bit version of php, which accepts int64

Browser other questions tagged

You are not signed in. Login or sign up in order to post.