在PHP中,fseek()函数用于在文件中设置读取或写入的位置
<?php $file = fopen('example.txt', 'r'); if ($file === false) { die('Error opening file'); } // 将文件指针移动到文件末尾 fseek($file, 0, SEEK_END); // 检查当前文件指针位置是否等于文件大小 if (ftell($file) === feof($file)) { echo "File pointer is at the end of the file."; } else { echo "File pointer is not at the end of the file."; } // 将文件指针移回文件开头 fseek($file, 0, SEEK_SET); fclose($file); ?> 在这个示例中,我们首先打开一个名为example.txt的文件。然后,我们使用fseek()函数将文件指针移动到文件的末尾(偏移量为0,起始位置为SEEK_END)。接下来,我们使用ftell()和feof()函数检查文件指针是否位于文件末尾。最后,我们将文件指针移回文件的开头,并关闭文件。