Writing variables to a file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Writing variables to a file

Post 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...
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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()
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post 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...
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Check out the write_ini_file functions in the notes here:

http://us2.php.net/manual/en/function.p ... i-file.php
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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");
zinc
Forum Newbie
Posts: 15
Joined: Fri Feb 10, 2006 1:02 am

Post 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
Post Reply