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 "\r\n". After getting the first line, the script removes it.
Bu, bu şekilde yapılır:
$contents = file_get_contents($file));
$first_line = substr($contents, 0, 32);
file_put_contents($file, substr($contents, 32 + 2)); //+2 because we remove also the \r\n
Açıkçası çalışır, ancak bunu yapmak için daha akıllı bir (veya daha fazla etkili) bir yolu olup olmadığını merak ediyorum?
Benim basit bir çözüm Ben temelde read and rewrite the entire file just to take and remove the first line.