In this tutorial we will be covering file handling in PHP.
Let's break this down!
fopen() is used to open files and make them readable/writeable. It takes two arguments, first the filename, then the mode. There are many different modes, but the most important are these:
file_get_contents() is used to read all content of a file into a string. It only needs the name of the file to be read as argument. Here we read the content of “myfile.txt”, which has been written by fwrite before and it gets assigned to the variable $filecontent which we echo afterwards.
After you are done working with a file, you should always use fclose() to close it. Simply give it the variable fopen() was defined to as argument and you’re good to go.
Any questions? Leave a comment or send me a message!