Function application skills in php file operations. 1. open the file: fopen (file name, mode); mode: r: Read-only r +: read/write w: Write-only. Open and clear the file content. If the file does not exist, create the file. W +: read/write. Open and clear
1. open the file: fopen ("file name", "mode ");
Mode:
R: Read-only
R +: Read/Write
W: write only. Open and clear the file content. If the file does not exist, create the file.
W +: read/write. Open and clear the file content. If the file is not saved, the file is created.
A: append. Open and write to the end of the file. If the file does not exist, a new file is created.
A +: Read/append. Write content to the end of the file to keep the file content.
2. close the file: fclose ();
For example:
- < ?
- $file=fopen("test.txt","r");
- //some code be executed
- fclose=($file);
- ?>
3. check whether the file end is reached: feof ();
Example: if (feof ($ file) {echo "end of file ";}
4. read files row by row: fgets ();
For example:
- $file=fopen("test.txt","r");
- while(!feof($file)){
- echo fgets($file)."< br/>";
- }
- fclose($file);
5. read files by character: fgetc ()
6. check whether the file exists: file_exists (); if yes, true is returned; otherwise, false is returned.
7. read the file to an array: $ array = file ("text.txt"), $ array [0] is the first line of text, and so on. If you want to flip the entire array, for example:
$ Arr = array_reverse ($ array );
The last line of text is $ arr [0].
To obtain the number of rows in the array $ array, use $ num = count ($ array );
To judge whether the text database is not empty, use: if ($ num> 0 ){}
Total number of calculated pages: $ total = ceil ($ num/$ pagesize) $ pagesize indicates the number of displayed pages.
Calculate the first record number displayed on the current page: $ number = ($ page-1) * $ pagesize;
Use "" as the separator to separate the data of every $ number unit in the array $ arr, and assign the data to the array $ rom
For ($ I = 0; $ I <= $ pagesize-1; $ I ++) {$ row = explode ("", $ arr [$ number];}
Assign the unit data in the data row to the variables in the brackets in order.
List ($ ip, $ datetime, $ name, $ email, $ home) = $ row
Bytes (file name, mode); mode: r: Read-only r +: read/write w: Write-only. Open and clear the file content. If the file does not exist, create the file. W +: read/write. Open and clear...