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

前端 未结 12 2251
天命终不由人
天命终不由人 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 03:54

    I came up with this idea yesterday:

    function read_and_delete_first_line($filename) {
      $file = file($filename);
      $output = $file[0];
      unset($file[0]);
      file_put_contents($filename, $file);
      return $output;
    }
    

提交回复
热议问题