// $Name is variable from input
$filename = "$name.txt";
// Does the file exist already?
if (!file_exists ($filename)
{
// No we make it.
$fp =fopen($filename,'w');
// Have array with $prefs
$allprefs = implode("|",$prefs);
fputs($fp,$allprefs);
// Close the file
fclose($filename);
}
else{
//it exists, so if we want to overwrite it do it as above if you want to read it, do as under.
$fp = fopen($filename,'r');
// You know how much prefs you have, set it good distance beyond that... 1024 should do at least.
$allprefs = fgets($fp,1024);
fclose($fp);
$prefs= explode('|',$allprefs);
}
// -the end-
If you have a bigger array, like twodimensional or something you probably need to do a loop, and do the fputs and implode within it for each row in that array.
Hope it helps.