Easy Tutorial
❮ Func String Convert Uuencode Func Cal Gregoriantojd ❯

PHP fopen() Function



Definition and Usage

The fopen() function opens a file or URL.

If fopen() fails, it returns FALSE and an error message. You can hide the error output by prefixing the function name with an '@'.

Syntax

Parameter Description
filename Required. Specifies the file or URL to open.
mode Required. Specifies the type of access you require to the file/stream. Possible values: "r" (opens for reading only, pointer at the beginning of the file)<br> "r+" (opens for reading and writing, pointer at the beginning of the file)<br> "w" (opens for writing, clears the file content, creates the file if it does not exist)<br> "w+" (opens for reading and writing, clears the file content, creates the file if it does not exist)<br> "a" (opens for writing, pointer at the end of the file, creates the file if it does not exist)<br> "a+" (opens for reading and writing, pointer at the end of the file, preserves file content)<br> "x" (creates and opens for writing, returns FALSE and an error if the file already exists)<br> "x+" (creates and opens for reading and writing, returns FALSE and an error if the file already exists)
include_path Optional. Set this parameter to '1' if you also want to search for the file in the include_path (specified in php.ini).
context Optional. Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream.

Tips and Notes

Note: When writing to a text file, ensure you use the correct line ending! On Unix systems, the line ending is \n; on Windows systems, it is \r\n; on Macintosh systems, it is \r. The text mode "t" on Windows transparently converts \n to \r\n. You can also use "b" to force binary mode, which does not transform the data. To use these flags, append "b" or "t" as the last character of the mode parameter.


Examples


❮ Func String Convert Uuencode Func Cal Gregoriantojd ❯