duanliang5051 2011-05-20 14:16
浏览 6
已采纳

如何在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
  • 写回答

5条回答 默认 最新

  • douji0588 2011-05-20 14:27
    关注

    Your explode() call is using 9 spaces as a separator, but your file only appears to have 5 spaces between each number. This means your $currentline be a single element array containing the original line, and not separate elements with a number in each.

    Either change the number of spaces in the explode call, or change to

    $currentLine = preg_split('/\s+/', $currentLine);
    

    which will split on any number of sequential spaces.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示