Using PHP to read files php I/O operations is not a little simpler than java. the same reading file java processing is cumbersome, and php is basically just a few pieces of code. From these aspects, php is really more convenient. this time I am sharing the php file operation to read several files. Method 1. reading common files is mainly about reading text files.
PHP's IO operations are not a little simpler than java's. the same reading of file java is complicated. php basically just comes out with a few pieces of code. From these points, php is really more convenient. this time I am sharing the php file operation to read several files.
1. reading common files is mainly about reading text files.
To read txt text files, php provides us with two common methods. let's start with the following code:
This method is best for reading small files. reading large files may have a great impact on apache, because the file is directly read. So it may be better to use the following
0) {$ str. = fread ($ fp, $ buf); $ tem + = $ buf;} echo $ str;} else {die ("file does not exist ");} fclose ($ fp);?>
2. read the resource file or configuration file
For resource files or configuration files, php also provides us with the appropriate method. I personally think php is a good way to read such files, so I can simply look at my resource files.
The following code is used to read the resource file.
$ Value) {echo "$ key: $ value "."
";}} Else {die (" The file does not exist ") ;}?>
Below is the program running
Is it easier to operate files than java?