How to read line by line in php

后端 未结 5 1246
北荒
北荒 2021-01-06 11:21

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 = @f         


        
5条回答
  •  时光说笑
    2021-01-06 11:59

    I would double check that there is not a new line at the end of the file. Maybe even double check inside of php that the line read is not blank.

    $lineCount=0;
    // while there is another line to read in the file
    while (!feof($file))
    {
        $lineCount++;
        // Get the current line that the file is reading
        $currentLine = fgets($file);
        if(trim($currentLine) != ''){
            $currentLine = explode('        ',$currentLine) ;
            insert($currentLine) ;
            echo "Inserted line number $lineCount
    "; } else { echo "There was a blank line at line number $lineCount.
    "; } }

提交回复
热议问题