I want to know the code for file handling function write(). Its should add a text in file from user input and shoe it to the screen in new window.Kindly if any one know the code reply here its urgent. Thanks.

Recommended Answers

All 4 Replies

in php, you would use echo.


$myVar = "A String";

echo ($myVar);


there are others... it all sort of depends on what you are trying to do.

If you want users to input data and put it on the screen, there are many ways to do that... it all sort of depends on what you want as a finished product, but they all generally follow this scenario..

1) send data with get or post (using a form or ajax call).
2) process the data.
3) spit something out (even if it's the same data that was sent in, or nothing.)

For example...
a php file called "myphp.php"...


if (isset($_GET['text']))
    if ($_GET['text'] != "whatever")
        echo ($_GET['text']);


You could use an HTML form to send your data...

<form method="GET" action="myphp.php" target="_blank">
<input type="text" name="text" />
<input type="submit" value="Submit" />

Now, that whole "open in a new screen" thing..

since your form is targetting "_blank" it will open in a new window (unless you have an iframe called "_blank"... but then you have different issues).

I think that's what youre asking...

Hope that helps,


Thanks bro for your coperation in my problem but actually I was asking about the file handling. Code for that is given below ....

I was asking that by using this code I want to show the text written in the text area on the screen on next page. I hope now you could understand what im sayiing and help me in this matter.

//php code

$file = $_POST['file_name'];
if($file == "")
  echo "please enter file name";
$fh= fopen($file,"w") or die ("Cannot open file or It is not loacated in the directory");

if ($fh) 

$fh1= fwrite($fh,($_POST["text"]));
echo $fh1;


//html code.........!
<form name="fecth" id="" method="post" action="proc2.php" enctype="multipart/form-data">
File name:<input type="text" name="file_name"  id="" value="" /><br /><br />
enter text:<textarea cols="20" rows="3"  name="text"></textarea><br /><br />
submit:<input type="submit" name="submit" id="" value="submit" />

Im not sure I follow what you are trying to do... are you trying to add to a file?

If you are adding to a file, you have to fwrite first, then fread to get the data back out.

In your example, I think that you are going to echo a boolean (true/false) as to whether or not the fwrite performed successfully...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.