Use the fopen() function to open a file or URL. If the function fails, it returns FALSE and an error message. Add '@' in front of the function name to hide error output.
fopen(file_path, mode, include_path, context)
file_path − The path to the file.
mode − The type of access you require to the file
incude_path − If you want to search for a file in include_path (in php.ini), Please set it to '1'.
context − The context of the file pointer.
The fopen() function returns FALSE and an error on failure. Add '@' in front of the function name to hide error output.
Suppose we have a file named "new.txt" with the following content.
The content of the file!
Now, let’s see an example -
The content of the file!
Let’s see an example of a “one.txt” file.
demo content
The above is the detailed content of fopen() function in PHP. For more information, please follow other related articles on the PHP Chinese website!