Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to open, read , wight and close a text file in php?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 312
    Comment on it

    Open a text file in PHP.

    To open a text file in PHP you will use fopen() funtion.

    $yourfile = fopen("yourtextfilepath", "r");// r is a mode that are used for read file.

    Read a text file in PHP.

    To read an opened file in PHP you will use fread() function.

    This function contains two parameter. First is filename and second is file size.

    echo fread($yourfile,filesize("yourtextfilepath"));

    Write text in text file in PHP.

    To write text in text file in PHP you will use fwrite() function.

    This function contains two parameter. First is filename and second is your text.

    $yourfile = fopen("yourtextfilepath", "w");// w is a mode that are used for writing in text file.
    $yourtext = "Name: Qazi Zawed Raza\n";
    fwrite($yourfile, $yourtext);

    Close text file in PHP.

    To close an open text file in PHP you will use fclose() function. In fclose() function only required file name to close.

    fclose($yourfile);

     

 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: