Home Tutorial Php Examples fwrite() example

 
 

Share on Google+Share on Google+
fwrite() example
Posted on: July 30, 2009 at 12:00 AM
Advertisement
Here you will learn about the example of fwrite().

The function fwrite()

Writing on a PHP file is an easy task and you can write any text on a PHP file using fwrite(); command. For writing on a PHP, first open that file and use function fwrite() in conditional statement. If the program finds the conditions true, it will print the desired texts otherwise not. 

For Example: In the below example, we are trying to print 'Develop Name:Varun Rai'. Lets see this example in steps:

First of all, begin the script with PHP tag;

Open the file on which the text has to be printed

begin the conditional statement with filename ();

Input the fwrite() command within the middle brackets,

check the condition;

Close the program with PHP tag.

<?php
$File_name = fopen("mytextfile.txt", 'w+');

if($File_name)
{
if(!fwrite($File_name, "Developer Name: Varun Rai"))
die("You can not write in the file.");

echo "Successfully writing to file";
}
?>
 

In the above program, if the file exists and runs properly, it will print "Developer Name:Varun Rai" and "Successfully writing to file", if failed to do so, the output will be "you can not write in the file".

Advertisement

Related Tags for fwrite() example:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 30, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com