Page 1 of 1

Writing variables to a file

Posted: Sun Mar 12, 2006 3:40 pm
by GeXus
Does anyone know how I could write a variable to a file? I understand how to write to files, but what if i wanted to write

Code: Select all

$row = $value;
and have it print this out? It wont do this, because it tries to replace these varialbes when writing...

Posted: Sun Mar 12, 2006 3:58 pm
by Burrito
I don't understand your question... do you want to write out a string and then write that string to a file?

if so, check out fwrite()

Posted: Sun Mar 12, 2006 4:05 pm
by GeXus
Well, I want to basically assign a variable to a value and write that to a file.. basically I want to write this to a file:

Code: Select all

$file = FILENAME
But it wont write the

Code: Select all

$file
because it in the fwrite, it just replaces this with its value...

Posted: Sun Mar 12, 2006 5:11 pm
by Buddha443556
Check out the write_ini_file functions in the notes here:

http://us2.php.net/manual/en/function.p ... i-file.php

Posted: Sun Mar 12, 2006 6:12 pm
by josh
Do you want to insert $file literally?

You should be able to just escape the variable if using double quotes

Code: Select all

fwrite($h,"the file is \$file");

Posted: Sun Mar 12, 2006 10:06 pm
by zinc
$ourFileName=$path."".$filename;
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fwrite($ourFileHandle,"what u want to write to the file?")

fclose($ourFileHandle);

w is write
a is append
r is read...there are still some other parameters available

hope this help