03-11-2006, 05:23 AM
microchip13 Wrote:
-------------------------------------------------------
> I tried using fopen and fwrite, which works,
> kinda.
> When it writes, it adds onto it, not copies over
> it,
> $handle1 = fopen('/tmp/sunupdown.txt', 'a');
> fwrite($handle1, $sun);
>
The 'a' means to append (add to) when writing to the file.
Maybe you want 'w' for a plain old writing to the file to overwrite the previous contents.
http://us2.php.net/manual/en/function.fopen.php
My solution outlined above would involve two parts.
Part 1. Create the file. You can do this either manually once for static variables or let your code create it using fopen() and fwrite(). Instead of plain data, you would write out a series of text lines that are the PHP code.
Part 2. Read in the file. Since the file is PHP, you could read it in and assign lots of variables in one operation using a 'require' statement as illustrated above.
Your method of writing raw data directly to a file is useful if you want to assign only one variable at a time. My method works for lots of variables stuffed into one file. I am sure there are other methods too that fall into a middle ground between the two we are discussing here. For example storing the data in an XML file is another option but probably more complicated than you need.
-------------------------------------------------------
> I tried using fopen and fwrite, which works,
> kinda.
> When it writes, it adds onto it, not copies over
> it,
> $handle1 = fopen('/tmp/sunupdown.txt', 'a');
> fwrite($handle1, $sun);
>
The 'a' means to append (add to) when writing to the file.
Maybe you want 'w' for a plain old writing to the file to overwrite the previous contents.
http://us2.php.net/manual/en/function.fopen.php
My solution outlined above would involve two parts.
Part 1. Create the file. You can do this either manually once for static variables or let your code create it using fopen() and fwrite(). Instead of plain data, you would write out a series of text lines that are the PHP code.
Part 2. Read in the file. Since the file is PHP, you could read it in and assign lots of variables in one operation using a 'require' statement as illustrated above.
Your method of writing raw data directly to a file is useful if you want to assign only one variable at a time. My method works for lots of variables stuffed into one file. I am sure there are other methods too that fall into a middle ground between the two we are discussing here. For example storing the data in an XML file is another option but probably more complicated than you need.