(1) Rewind () function
This function sets the pointer of the file handle to the beginning of the file stream, with the following syntax:
BOOL Rewind (Resource handle)
(2) fseek () function
The Fseek () function implements the positioning of the file pointer with the following syntax:
int fseek (Resource handle,int offset[,int whence])
The handle parameter is the file to open
Offset to the pointer position or relative whence of the parameter, which can be a negative value.
Whence includes the following three types:
A,seek_set, the position equals the offset byte.
b, seek_cur, position equals current position plus offset offset.
C, Seek_end, where the position equals the end of the file plus offset offsets.
If you omit the whence parameter, the system defaults to Seek_set.
(3) feof () function
This function is used to determine if the file pointer is at the end of the file, with the following syntax:
BOOL Feof (Resource Hanlde)
Returns true if the file pointer is to the end of the file, otherwise false
(4) Ftell () function
The Ftell () function is used to return the position of the current pointer in the following syntax format:
int Ftell (resource handle)
The sample code is as follows:
$filename="1.txt";if(Is_file ($filename)) {Echo"Total Files bytes:". FileSize ($filename)."
";$handle=fopen ($filename,"RB");Echo"The end of the pointer's initial position:". Ftell ($handle)."
"; Fseek$handle, -);//Move pointer positionEcho"The position of the pointer after using the fseek () function:". Ftell ($handle)."
";Echo"Output the contents after the current pointer:". fgets ($handle)."
";if(Feof ($handle)) {Echo"Current pointer points to end of file". Ftell ($handle)."
"; }Else{Echo"The current pointer does not have an ambition end:". Ftell ($handle)."
"; } Rewind ($handle);Echothe current pointer points to the position after using the rewind () function: ". Ftell ($handle)."
";Echo"Output after 25 bytes:". fgets ($handle, -)."
"; Fclose$handle);}Else{Echo"file does not exist";}?>
The results of the operation are as follows:
2, File lock
When you write to a file, you need to lock the file to prevent other users from modifying the file at the same time. In php, file locks are implemented using the flock () function. The syntax is as follows:
BOOL Flock (int handle,int operation)
Handle is an already opened file pointer, the operation parameter is as follows:
The example code for locking, writing, and unlocking closed files is as follows:
$filename ="1.txt";$handle =fopen($filename"w");flock($handle, LOCK_EX);$str ="MMMMMMMMMMMMMMMMMMMMM";fwrite($handle$str);flock($handle, LOCK_UN);fclose($handle);readfile($filename);?>
The results of the operation are as follows:
The above describes the PHP development of the file pointer, file lock, including the content of the area, I hope that the PHP tutorial interested in a friend helpful.