PHP技术交流QQ群:490910618
1 $line = ''; 2 3 $f = fopen('data.txt', 'r'); 4 $cursor = -1; 5 6 fseek($f, $cursor, SEEK_END); 7 $char = fgetc($f); 8 9 /** 10 * Trim trailing newline chars of the file 11 */ 12 while ($char === "\n" || $char === "\r") { 13 fseek($f, $cursor--, SEEK_END); 14 $char = fgetc($f); 15 } 16 17 /** 18 * Read until the start of file or first newline char 19 */ 20 while ($char !== false && $char !== "\n" && $char !== "\r") { 21 /** 22 * Prepend the new char 23 */ 24 $line = $char . $line; 25 fseek($f, $cursor--, SEEK_END); 26 $char = fgetc($f); 27 } 28 29 echo $line;转自:https://q.cnblogs.com/q/76347 JackWang-CUMT 的回答