First create a php file named file and add tags.
Create a txt file named myfile and use the touch function to create the file. After running, a myfile document file will be generated in the same directory as php.
Related recommendations: "php introductory tutorial"
Use the fopen() function to Open the myfile document and assign values.
Then write the content into the myfile document. If you want to write multiple entries, just execute it multiple times.
Re-open the myfile file. This is used to read the file.
After reading the myfile file, use a loop to read the contents of the file and output it.
Finally execute the filephp file, you will find that text is sucked into the document, and the browser will read the content of the document.
The above is the detailed content of How to create, read and write files in php?. For more information, please follow other related articles on the PHP Chinese website!