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条)

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch