Easy learning with example program codes

PHP Write File

Writing data in a file is another common feature of file handling. In PHP, there are various modes that facilitates different ways and features of writing data into a file, including: w, r+, w+, x, x+, c or c+ mode. PHP also supports some functions to write to a file.

PHP Write File functions are:

  • PHP fwrite()
  • PHP fputs()

PHP fwrite() function:

To write a file in PHP, fwrite() function is used.


int fwrite ( resource $filename , string $string )  

  • Filename: This parameter represents the name of the file to write to.
  • String: This parameter represents the string to be written.


<!DOCTYPE html>
$samplefile = fopen("phpfile.txt", "w");  
fwrite($samplefile, "Hello PHP!");  
$samplefile = fopen("phpfile.txt", "r");
echo fread($samplefile, filesize("phpfile.txt"));


Hello PHP!
Posted in PHP   

Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at


We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki