Create a Text File

From Phpmaniac

Jump to: navigation, search

Return to Contents

Create a new file

PHP makes creating a text file simple. All we need to do is open the file, write some contents, then close it.

  1. <?php
  2.    $file = fopen("test.txt", "w+"); // Open the file
  3.    fwrite($file, "Hello World!");   // Write to the file
  4.    fclose($file);                   // Close the file
  5. ?>

Return to Contents

Personal tools