Click to See Complete Forum and Search --> : fwrite help


Conor
02-25-2004, 02:31 PM
ok i have like 7 variables. and i have this if (!fwrite($handle, $text1)) {
echo "Cannot write to file ($filename)";
exit;
}



but whenever i try to write ore then one variable it doesnt work. how would i do this.

Sam
02-25-2004, 04:46 PM
you have to fclose($handle);

Conor
02-25-2004, 04:58 PM
i do that later in the script. The script works its just i can only get it to write one variable at a time and i need to write like 7

Sam
02-25-2004, 05:00 PM
you have to do it for each file you open before you try to open another

Conor
02-25-2004, 05:04 PM
i dont think you understand what i mean. i want to right it all to the file example.txt but i want to write all my variables

Sam
02-25-2004, 05:45 PM
ah, thought you were saying you wanted to write to multiple files
you shouldn't use fwrite more than once.
instead, get all your files into one big string ie. $var1 . "\n" . $var2 . "\n"
then fwrite that

Conor
02-25-2004, 06:56 PM
ah i dont how to do that.

$sname1
$rname1
$loc1
$email1
$aim1
$text1
$ipadd1

thats the names of all my variables. How would i put into just "$var1"

Sam
02-25-2004, 06:57 PM
$var1=$sname1 . "\n" . $rname1 . "\n" . $loc1 . "\n" . $email1 . "\n" . $aim1 . "\n" . $text1 . "\n" . $ipadd1 . "\n"

this will add them all to $var1 with newlines between each variable in the txt file

Conor
02-25-2004, 07:00 PM
ill go try that, thank you.

Conor
02-25-2004, 07:04 PM
thanks so much it works and i learned something new!