1

I have the follow code which are reading an CSV file using codeigniter by PHP:

            //Upload to server:
            $config['upload_path'] = './tmp/';
            $config['allowed_types'] = 'gif|jpg|png|doc|txt|csv';
            $config['max_size'] = 1024 * 8;
            $config['encrypt_name'] = TRUE;

            $csv_move_path = $this->config->item('directory')."/destination/";

            $this->load->library('upload', $config);
            $this->upload->do_upload('name_of_csv');
            $this->upload->data();

            move_uploaded_file($_FILES["file"]["tmp_name"], $csv_move_path . $_FILES["file"]["name"]);

            $path = $csv_move_path . $_FILES["file"]["name"];

            //Reading CSV
            $fields;            /** columns names retrieved after parsing */
            $separator = ';';    /** separator used to explode each line */

            $lines = file($path);

            //Loop of lines
            foreach( $lines as $line_num => $line )
            {

                    if(!empty($line)){ // skip empty lines

                        $content = explode($separator, trim(str_replace('\'', '', $line)));

                        //Save line on DB
                        $this->model->addInformation($header_array,$content);

                    }}

My problem is when I have a very long numbers it automatically converts to scientific notation, so when I read in PHP it takes 3,53E+14, instead of 352564000000000, can someone help how can I read the entire number and not the scientific notation?

PS: I have already transform the field to text on CSV file, using Excel

  • possible duplicate of [Prevent Excel from reformatting text in the scientific notation](http://stackoverflow.com/questions/18816995/prevent-excel-from-reformatting-text-in-the-scientific-notation) – Saty Apr 09 '15 at 13:15
  • Unfortunately no, because the guy who answered the question said to put the `=CONCATENATE` function in the Excel, and in my case another person will put the file as it is, the file is giant and the person will have a lot of work just to use this function in each line who has scientific notation =/, but I appreciate your help @satishrajak – Felipe Campanhol Apr 09 '15 at 13:37
  • 2
    read from here hope it will help you http://superuser.com/questions/234997/how-can-i-stop-excel-from-eating-my-delicious-csv-files-and-excreting-useless-da – Saty Apr 09 '15 at 13:46
  • Thanks a lot @satishrajak, the page you shared with me makes me realize that the Excel had been "corrupting" the file, so, if I create a new .CSV from notepad++ for example, the PHP will read them as it is, and not by scientific notation. – Felipe Campanhol Apr 10 '15 at 18:00

0 Answers0