How can fseek() and SEEK_END be used to manipulate the file pointer in PHP?
To manipulate the file pointer in PHP using fseek() and SEEK_END, you can seek to a specific position relative to the end of the file. This can be useful for tasks such as appending data to the end of a file or reading data from the end of a file. By using fseek() with SEEK_END as the second parameter, you can move the file pointer to the end of the file and then seek a specific number of bytes before or after the end.
$file = fopen("example.txt", "r+");
// Move the file pointer 10 bytes before the end of the file
fseek($file, -10, SEEK_END);
// Read the last 10 bytes of the file
$data = fread($file, 10);
echo $data;
fclose($file);
Keywords
Related Questions
- How can the issue of not receiving output be resolved in the given PHP script?
- How can one ensure that all image references are correctly set when transitioning from framesets to PHP for website development?
- What are the potential pitfalls when trying to outsource a SELECT query in PHP and how can they be avoided?