Is this the most efficient way to get and remove first line in file?

前端 未结 12 2245
天命终不由人
天命终不由人 2020-12-03 03:53

I have a script which, each time is called, gets the first line of a file. Each line is known to be exactly of the same length (32 alphanumeric chars) and terminates with \"

12条回答
  •  离开以前
    2020-12-03 04:10

    I think this is best for any file size

    $myfile = fopen("yourfile.txt", "r") or die("Unable to open file!");
    $ch=1;
    
    while(!feof($myfile)) {
      $dataline= fgets($myfile) . "
    "; if($ch == 2){ echo str_replace(' ', ' ', $dataline)."\n"; } $ch = 2; } fclose($myfile);

提交回复
热议问题