On Mon, May 14, 2001 at 03:05:30PM +0100, Tarrant Costelloe wrote:
> What's the most basic syntax for writing to a text file using PHP. I would
> like to store some variables in one and then retrieve them a later stage...?

This will append This is pretty basic to the end of the file instead of
overwriting the file.

<?php
$basic = fopen("basic.txt", "a+");
fputs($basic, "This is pretty basic\n");
fclose($basic);
?>

It is really easy to read in the entire file into an array.  Probably
not very efficient, but will get you started quickly.

<?php
$prettyBasic = file("basic.txt");
for($i = 0; $i < sizeof($prettyBasic); $i++) {
   echo "$prettyBasic[$i]<br>";
}
?>

Search the online manual for more information on these functions.

> 
> Taz
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 

-- 
Jason Stechschulte
[EMAIL PROTECTED]
--
If I don't document something, it's usually either for a good reason,
or a bad reason.  In this case it's a good reason.  :-)
             -- Larry Wall in <[EMAIL PROTECTED]>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to