• Have Any Question?
  • contact@eitworld.com

PHP File Write

    • We have to use the function “fopen” to open the file for writing.

$myFile = "write.txt";
$myfilehandle = fopen($myFile, 'w');

c language features

    • The fwrite function allows data to be written to any type of file.
    • fwrite function takes two parameter : first parameter is the file handle and its second parameter is the string of data that is to be written.
    • Here is an example which shows the use of fwrite function:

$myFile = "write.txt";

$myfilehandle = fopen($myFile, 'w') or die("can't open file");

$stringData = "Ram Sharman";

fwrite($myfilehandle, $stringData);

$stringData = "Sohan Laln";

fwrite($myfilehandle, $stringData);


    • The $myfilehandle variable contains the file handle for write.txt. The file handle knows the current file pointer, which for writing, starts out at the beginning of the file.
    • We wrote to the file write.txt twice. Each time we wrote to the file we sent the string $stringData that first contained Ram Sharma and second contained Sohan Lal. After we finished writing we closed the file using the fclose function.
    • If you were to open the write.txt file in NOTEPAD it would look like this:.

Ram Sharma
Sohan Lal

application of c language

    • Now that write.txt contains some data we can demonstrate what happens when you open an existing file for writing. All the data contained in the file is wiped clean and you start with an empty file. In this example we open our existing file write.txt and write some new data into it.

$myFile = "write.txt";

$myfilehandle = fopen($myFile, 'w') or die("can't open file");

$stringData = "Mohan Verman";

fwrite($myfilehandle, $stringData);

$stringData = "Shyam Duan";

fwrite($myfilehandle, $stringData);


    • If you now open the write.txt file you will see that Ram Sharma and Sohan Lal have both vanished, as we expected, and only the data we just wrote is present.

Mohan Verma
Shyam Dua

Overview of Compiler and Interpreters

Before talking about the Compiler and Interpreter we have to know some important points as given below:

  • A program is a set of instructions used to perform a particular task.
  • These programs are written in assembly language or high level language (English words),this written program is called as source program which cannot be understood by the computer. Computer can only understand the instructions available in the form of machine language as ‘0’ and ‘1’.
  • The source program is to be converted to the machine language that is known as object program.
  • Source program is converted into object program with the help of interpreter or compiler which are explained here in detail:


  • Compiler reads the entire source program and converts it into the object program.
  • Compiler provides errors of entire program at once instead of providing them line by line. Only error free program can be executed.
  • Compiler consumes less time for converting source program to object program.
  • Compiler is preferred where length of the source program is very large.


  • Interpreter reads only one line of source program at a time and converts it into the object code.
  • Interpreter provides error line by line.
  • Interpreter consumes more time for converting source program to object program than compiler.

Real Time Web Analytics