October 17th, 2000, 08:12 PM
I'm setting up an script that will send mail to an address given by a user. The problem is that the body of the e-mail varies depending on a few responses that the person gives, and writing out like 1000 lines of code just to get each of the outcomes covered is not my idea of fun. My question is, is there any way to make a variable in PHP the contents of a .txt file so I don't have to have that big of a script? Thanks in advance!
October 17th, 2000, 08:17 PM
$fp = fopen("/path/to/file.txt", "r");
$contents = fread($fp, filesize("/path/to/file.txt"));
Then then contents of the file would be in $contents.
October 17th, 2000, 08:41 PM
God, I really need to read a PHP manual or something like that sometime so I can stop asking these stupid questions. Thanks #6!
October 18th, 2000, 02:19 AM
yes that would be good .. hehe
The PHP manual is very good. If you need to look up a function, go to http://www.php.net/whateverfunction and it takes you straight to the man page for that function.
October 18th, 2000, 02:50 AM
with fopen you'll place the contents of the file in a string! that could not be a problem
but if you wanna do something with that string is hard!
instead if you do
$contents = file("myfilename.txt")
it places myfilename in an array, here in $contents
so $contents contains the first line in the txt file!
this could be handy sometimes
October 18th, 2000, 03:13 AM
I concur hehe