This tutorial provides a lot of information about how to use php to operate files, if a file is intercepted, read the file content, format the output file content, lock the file function, and open the file in writing mode, this tutorial provides a lot of instructions on how to use php to operate the file, if a file is intercepted, read the file content, format the output file content, lock the file content, and open the file in writing mode.
Script ec (2); script
Csv files.
*/
Using fpw.fopen('test.txt ', 'R'); // open the file
$ Flag = ftruncate ($ fp, 5); // capture a file
If ($ flag) // determines whether the object is intercepted successfully
{
Echo "the file has been intercepted! ";
}
Else
{
Echo "An error occurred while intercepting the file! ";
}
Fclose ($ fp); // close the file
/*
*/
Using fpw.fopen('test.txt ', 'R'); // open the file in read-only mode
$ Data = fgets ($ fp, 4096); // read the file content
Fseek ($ fp, 100); // move the file pointer to the first offset bit.
Fclose ($ fp); // close the file
/*
*/
$ Fp = fopen ("test.txt", "r"); // open the file
$ Contents = fscanf ($ fp, "% st % sn"); // format the output file content
Print_r ($ contents); // output content
Fclose ($ fp); // close the file
/*
*/
Foreach (glob ("*. txt") as $ filename)
{
Echo "file name:". $ filename;
Echo"
";
Echo "file size:". filesize ($ filename). "n ";
Echo"
";
}
// Match all text files
Function lockfile ($ fp) // User-Defined lock file function
{
Flock ($ fp, lock_ex) or die ("cannot flock file"); // locked exclusively, only the current process can access the file
}
Function unlockfile ($ fp) // custom unlock function
{
Flock ($ fp, lock_un) or die ("cannot unlock file"); // release lock
}
$ Fp = fopen ("test.txt", "w +"); // open the file
Lockfile ($ fp); // lock the file
Fwrite ($ fp, "hello, php tutorial"); // write the file
Unlockfile ($ fp); // unlock
Fclose ($ fp); // close the file
//
$ File = "test.txt"; // definition file
$ Fp = fopen ($ file, "w"); // open the file as a write
$ Date = "hello world! "; // Define a string
Fputs ($ fp, $ date); // write the string to the specified file
Fclose ($ fp); // close the file
//
$ List = array (
'A, B, c, D ',
'1, 2, 3'
); // Define an array as the input function parameter
Export fp1_fopen('test.csv ', 'w'); // open a csv file as a write
Foreach ($ list as $ line) // traverses the array and writes the csv file with "," as the delimiter
{
Fputcsv ($ fp, split (',', $ line ));
}
$ Date = fread ($ fp, 4096); // read the file content
Echo $ date; // output file content
Fclose ($ fp); // close the file
//
$ Fp = fopen ("test.txt", "r"); // open the file
Echo fpassthru ($ fp) // read file data to the buffer zone
Fclose ($ fp); // close the file