CodesJava

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.

Syntax:

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.

Example:

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

Output

Hello PHP!
Posted in PHP   
Sign Up/ Sign In
Ask a Question


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 hr@codesjava.com.

Development

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

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki