dsue14118 2017-08-02 21:35
浏览 147
已采纳

如何使用php从文本文件中排除第一行

My text file sample.txt. I want to exclude the first row from the text file and store the other rows into mysql database.

ID Name EMail

1  Siva xyz@gmail.com

2 vinoth xxx@gmail.com

3 ashwin yyy@gmail.com

Now I want to read this data from the text file except the first row(ID,name,email) and store into the MYsql db.Because already I have created a filed in database with the same name.

I have tried
$handle = @fopen($filename, "r"); //read line one by one

while (!feof($handle)) // Loop till end of file.
{
    $buffer = fgets($handle, 4096); // Read a line.
}
print_r($buffer); // It shows all the text.

Please let me know how to do this?

Thanks. Regards, Siva R

  • 写回答

2条回答 默认 最新

  • dotelauv682684 2017-08-02 21:56
    关注

    You can just call fgets once before your while loop to get the header row out of the way.

    $firstline = fgets($handle, 4096);
    while (!feof($handle)) // Loop till end of file.
    { ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器