i
PHP Variables
PHP Data Types
PHP Echo & Print
PHP Strings
PHP Numbers
PHP Constants
PHP Operators
PHP if...else...elseif Statements
Switch Statement
PHP Loops
PHP Arrays
Superglobals
PHP Coding Standards
PHP Form Handling
PHP Form Validation
PHP URLs Validation
PHP Form Required Validation
Complete Form Example
PHP File Functions Open/Read
PHP File Create/Write
PHP File Upload
PHP Cookies Handling
PHP Session Handling
PHP filter_var() Function
PHP Validation Filters
PHP Sanitization Filters
Using Filters
Filters Advanced
JSON
PHP Date and Time
MySQL Database
MySQL Connect
MySQL Commands-Creating a Table
MySQL Commands-Inserting The data
MySQL Commands-Prepared Statement
MySQL Commands-Selecting The Data
MySQL Commands-Where and Order By
MySQL Commands-Deleting And Updating The Data
PHP-OOP Introduction
PHP-Classes/Objects
PHP-Constructor/Destructor
PHP-Access Modifiers
PHP-Inheritance
PHP-Inheritance and Protected Access Modifier
PHP-Overriding Inherited Methods
PHP-Final keyword
PHP-Abstract Classes
PHP-Constants
PHP-Traits
PHP-Static Methods and Properties
Introduction to Functions
Defining A function
Returning Values From A Function
Dynamic Function Calls
Variable Scope
Understanding Arguments Or Parameters
Testing For A Function Existence
Returning Multiple Values From A Function
Making practical Use By Building Code Libraries For Code Re-usability
Using Include() And Require()
You can create a file using fopen() function in PHP by using w or a mode that allows you to create a new file and write it. If you use fopen() function with a file that is not present currently, it will create a new file and open it for writing or appending.
For example: $new_file = fopen(“mynewfile.txt”);
To write a file, you can use fwrite() function and it accepts two parameters. First parameter specifies the name of the file and second parameter specifies the text that needs to be written to the file.
For example:
$text = “ This is my new file”;
fwrite($new_file, $text);
fclose($new_file);
The output of the above file will be: This is my new file
if you use fopen() function again with w mode, the existing data of the file will be removed, and the new contents will overwrite the existing data in the file as w mode will erase the data and open the file for writing.
For example:
$new_file = fopen(“mynewfile.txt” , “w” );
$text = “ Welcome to file writing functions \n”;
fwrite($new_file, $text);
$text = “ We have overwritten the existing file.”);
fwrite($new_file, $text);
fclose($new_file);
?>
The output of the above php script will be:
Welcome to file writing functions
We have overwritten the existing file.
Don't miss out!