+ 1
Fopen('r') vs File() PHP
Just finished the php course and have one question that was not discussed in the comments sections throughout. You can use the mode to open files for read only: fopen("filename.text", 'r'); But based on the PHP course, you use file("filename.text"), since that returns an array for you to use in an attempt to access the files. My question then is, what would you use fopen('r') for, if you can't write to it and is read from using file()? My assumption is that you can do $var = fread($file, 'file'); but I don't know if such a function even exists. I'll also google this 😅
5 odpowiedzi
+ 1
something like this?
https://code.sololearn.com/wmfur605Ew1W/?ref=app
+ 1
I'm not sure I understand some points of your thread, even so, this thread clarifies a part of it:
https://stackoverflow.com/questions/24007898/difference-between-file-file-get-contents-and-fopen-in-php
+ 1
Since I do not develop professionally with PHP I can not answer with certainty, but I usually use it to open all the files. For me it is much more comfortable to read them through the stream.
File() is a high-level function, but I do not like to manipulate the contents of the file as an array. I find it impractical in many situations, especially because all operating systems use a different line break.
0
Just confused on how to use fopen("file.txt", "r");
0
I could not have any examples of using it with 'r' online.
If you have time, can you give any?