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

如何使用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条)

报告相同问题?