Log in

View Full Version : how to save text in PHP..? need help asap...



oliverzimmerman
05-20-2008, 06:42 PM
Hi...

in PHP code,
How can I save text? and to read text file and fill in text area?
can you please share just a piece of code....I really need it..asap!!!

thanks in advance....

thetestingsite
05-20-2008, 07:58 PM
To read text (and output to browser):



<?php
echo file_get_contents('file.txt');
?>


to save text:



<?php

$content = 'This is a test text file saved by using a php script!';

$fp = fopen('file.txt', w);
fwrite($fp, $content);
fclose($fp);


For more information, visit php.net's website and look up the following commands:

fopen, fwrite, file_get_contents, file

Hope this helps.