Laravel PHP Programming

fopen() function (Create a new file With PHP)

The fopen() method in PHP is a library function that is used to open a file to perform various operations which include reading, writing etc. along with various modes. If the file exists then the particular file is opened else a new file is created.

$myfile = fopen("testfile.txt", "w")

Reference:- Click Here

Parameters: The method accepts two parameters of character type:
  1. file_name: This is of C string type and accepts the name of the file that is needed to be opened.
  2. mode_of_operation: This is also of C string type and refers to the mode of the file access. Below are the file access modes for C:
    1. “r” – Searches file. If the file is opened successfully fopen() loads it into memory and sets up a pointer which points to the first character in it. If the file cannot be opened fopen() returns NULL.
    2. “w” – Searches file. If the file exists, its contents are overwritten. If the file doesn’t exist, a new file is created. Returns NULL, if unable to open the file.
    3. “a” – Searches file. If the file is opened successfully fopen() loads it into memory and sets up a pointer that points to the last character in it. If the file doesn’t exist, a new file is created. Returns NULL, if unable to open the file.
    4. “r+” – Searches file. If opened successfully, fopen() loads it into memory and sets up a pointer which points to the first character in it. Returns NULL, if unable to open the file.
    5. “w+” – Searches file. If the file exists, its contents are overwritten. If the file doesn’t exist a new file is created. Returns NULL, if unable to open the file.
    6. “a+” – Searches file. If the file is opened successfully fopen( ) loads it into memory and sets up a pointer which points to the last character in it. If the file doesn’t exist, a new file is created. Returns NULL, if unable to open the file.

 

Related Blogs

Install Xammp in Windows

 

 

Related posts

Arrays In PHP

codebugs@admin

What is a Function And Types of Function in PHP.

codebugs@admin

How To GET XML file in PHP

codebugs@admin

Leave a Comment