How to read a file in PHP

preview_player
Показать описание
We have to open a file, then we can read the file, and finally we have to close the file. Let's explain step by step.

First, we open the file using function fopen() that contains two parameters. First parameter is the file name, and second parameter is the mode of opening that is "r" in our case which stands for reading.

Finally, we are closing the file pointer using fclose() function that accepts one parameter which is the file pointer.
fclose($file);

Here is the full three lines example at a glance.
fclose($file);

Alternatively, we can use readfile() function to read the entire content of a file. The readfile() takes the file name as the parameter and extract the entire content and display. Here is an example.
Рекомендации по теме
visit shbcf.ru