Hi,
How do you assign all the contents in a file to a variable?
thanks
| SitePoint Sponsor |





Hi,
How do you assign all the contents in a file to a variable?
thanks
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein
PS this is not my code. I found it at:Code:if ($file = fopen($filename, "r")) { $contents = fread($file,filesize($filename)); fclose($file); } else { /* file doesn't exist */ }
http://www.phpbuilder.com/mail/php3-...99805/1377.php
But it looks right![]()





Thanks!
How do you print someting onto a file while overwirting everything else?
Thanks for your help!
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein





$fp = fopen("filetowriteto", "w");
fwrite($fp, $data);
fclose($fp);
the w arg in the fopen statement can take many forms the most common are
w - open a file for writing(wipes out old data)
a - open a file for appending(appends data onto exisintg)
r - open a file for reading
Please don't PM me with questions.
Use the forums, that is what they are here for.





Hmm....
How do you print, for example
0|0
?
fwrite( $str, $str2);
?
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein





okay.
thanks I get it now
was wondering whats the first variable for fwrite was for..hehez
thnaks~
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein





$data = "0|0";
$fp = fopen("filetowriteto", "w");
fwrite($fp, $data);
fclose($fp);
Please don't PM me with questions.
Use the forums, that is what they are here for.
Bookmarks