Open a text file in PHP.
To open a text file in PHP you will use fopen() funtion.
$yourfile = fopen("yourtextfilepath", "r");// r is a mode that are used for read file.
Read a text file in PHP.
To read an opened file in PHP you will use fread() function.
This function contains two parameter. First is filename and second is file size.
echo fread($yourfile,filesize("yourtextfilepath"));
Write text in text file in PHP.
To write text in text file in PHP you will use fwrite() function.
This function contains two parameter. First is filename and second is your text.
$yourfile = fopen("yourtextfilepath", "w");// w is a mode that are used for writing in text file.
$yourtext = "Name: Qazi Zawed Raza\n";
fwrite($yourfile, $yourtext);
Close text file in PHP.
To close an open text file in PHP you will use fclose() function. In fclose() function only required file name to close.
fclose($yourfile);
0 Comment(s)