Re: best way to save program prefs to a file?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Are you wanting the preferences to be real-time changeable?  For example, 
user preferences that can be modified then saved?  If so, just store them in 
an array, then serialize the array and save it to a file.  Read the file at 
every page load.

[code]

//save the settings
$user_settings['setting1'] = 'foo';
$user_settings['setting2'] = 'bar';

$fh = fopen('user_settings.dat');
$serialized = serialize($user_settings);
fwrite ($fh, $serialized, strlen($serialized));
fclose($fh);

//reload the settings
$user_settings = unserialize(file_get_contents('user_settings.dat'));


[/code]


Hope this helps.

-- 

Sincerely,

A.J. Brown



"Jay Blanchard" <jay.blanchard@xxxxxxxxxxx> wrote in message 
news:0CEC8258A6E4D611BE5400306E1CC92708D47293@xxxxxxxxxxxxxxxxxx
> [snip]
> I'd like to save some program preferences to a txt file where they can be
> recalled and updated at a later time. Basically this will be a variable 
> name
>
> and a value. Can someone suggest a reference or method to best perform 
> this
> task?
> [/snip]
>
> Open a new file, save stuff to it, close the file.
> Include the file where you need the prefs.
>
> http://www.php.net/fopen
> http://www.php.net/explode 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux