Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read line by line in php

Tags:

php

when i try to insert each line into my oracle database i get an error stating invalid number, but if have only one line in the file it works fine.

$file = @fopen('file.text', "r") ;  


// while there is another line to read in the file
while (!feof($file))
{
    // Get the current line that the file is reading
    $currentLine = fgets($file) ;
    $currentLine = explode('        ',$currentLine) ;
    insert($currentLine) ;


}   

fclose($file) ;

the lines look like this

1     4     100
1     4     101
like image 941
Technupe Avatar asked Dec 27 '22 20:12

Technupe


1 Answers

Try this:

$currentLine = trim(fgets($file)); 

It's possibly failing on the newline/carriage-return at the end of the line.

If not, where is this insert() function defined? Build a debug section that echos or writes out the attempted queries so you can really see the issue.

like image 99
Fosco Avatar answered Dec 30 '22 11:12

Fosco