#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Omaha
    Posts
    5
    Rep Power
    0
    Hi,

    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!

    Michael
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Melbourne, Victoria, Australia
    Posts
    104
    Rep Power
    14
    Easy.

    $fp = fopen("/path/to/file.txt", "r");
    $contents = fread($fp, filesize("/path/to/file.txt"));
    fclose($fp);

    Then then contents of the file would be in $contents.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Omaha
    Posts
    5
    Rep Power
    0
    God, I really need to read a PHP manual or something like that sometime so I can stop asking these stupid questions. Thanks #6!

    Michael
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Melbourne, Victoria, Australia
    Posts
    104
    Rep Power
    14
    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.
  8. #5
  9. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    6
    Rep Power
    0
    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[0] contains the first line in the txt file!
    this could be handy sometimes

    laterz
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Melbourne, Victoria, Australia
    Posts
    104
    Rep Power
    14
    I concur hehe

Similar Threads

  1. help with tables and wordwrapping
    By junkedBrian613 in forum PHP Development
    Replies: 2
    Last Post: February 15th, 2004, 05:42 PM
  2. Possible to read in value from a text file?
    By discus18 in forum PHP Development
    Replies: 2
    Last Post: February 6th, 2004, 11:19 PM
  3. Simple find and replace word search for a text file with php?
    By rabid lemming in forum PHP Development
    Replies: 4
    Last Post: February 1st, 2004, 09:37 PM
  4. How to read multiple line text file into a variable
    By gatewaycityca in forum Visual Basic Programming
    Replies: 4
    Last Post: January 29th, 2004, 12:26 PM
  5. Need help with logging to a text file...
    By Mason in forum PHP Development
    Replies: 8
    Last Post: January 28th, 2004, 05:34 PM

IMN logo majestic logo threadwatch logo seochat tools logo