Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Writing a file in PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 104
    Comment on it

    File handling in php allow us to make operation to write in a file .So we can write a new file or we can append text to an already existing file.For this we have fwrite() function in PHP.

    Syntax is : -

    fwrite(file,string,length);
    

    parameters are:-

    file - Required. it allow there is an open file we have to write to.

    string - Required. It allow string to write in a opened file.

    length - Optional. It allow the max limit of bytes to write in a file.

    NOTE : - If there is third parameter included in the fwrite() function, then writing in a file will stop just after the given value of length parameter .


    Example for writing in a file : -

    <?php
       $filename = "/home/user/guest/newfile.txt";
       $file = fopen( $filename, "w" );
    
       if( $file == false )
       {
          echo ( "Error in opening new file" );
          exit();
       }
       fwrite( $file, "This is  a simple test\n" );
       fclose( $file );
    ?>
    

 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: