Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • File Create/Write in PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 118
    Comment on it

    Create File in PHP

    To create a file in PHP fopen() function is used i.e., the function that is used to open a file is also used to create a file. If we use, fopen function() to open a file and file doesn't exist, it will create a new file. For example:

    $filename=fopen("demo.txt","w")
    

    Write to File in PHP:

    To write in a file in PHP fwrite() function is used. This function contains two parameters:

    • first parameter is the name of the file to write to
    • second parameter is the string to be written to the file.

    For example:

    <?php
    $filename = fopen("demo.txt", "w") or die("Unable to open file!");
    $filetxt = "Writing to a file in PHP\n";
    fwrite($filename, $filetxt);
    $filetxt = "Again writing to a file\n";
    fwrite($filename, $filetxt);
    fclose($filename);
    ?>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: