Read and Write text file in PHP

In many Websites we develop, most of them use the log system so we can map system points to be analyzed later, such as a connection failure, attempts to access a restricted place … Anyway there are many possibilities of use a log file.

For this we will use only three functions, which is the fopen to open the file, fwrite to write to the file, and fclose to close the file.

The first step is to define the name of the file in which we will do read write operations (or what is the name of file to be created), in our example will specify a suggestive name like “file.txt” and add it to a variable “$file”.

In our example we will insert the text “Hello. is awesome website for freshers ” for this we create¬† variable “$text” .

Continue reading