Jump to content


This topic is now archived and is closed to further replies.


Problems with including a text file

Recommended Posts

I'm struggling with some code. There are 2 separate scripts I wish to make. First, I have a file, which for the sake of this topic am going to refer to as filetoinclude.txt. I need a script with a basic form that has a single line in a form and a submit button that will change the text in this file.

The second part I already have a script for, but I want to define a variable as the contents of that text file. So assuming filetoinclude.txt has only the following "Testing Text", I just want to define variable $var as whatever the text is in the text file. Basically this is what I have for defining:

[code] $MOTD = @include("path/to/filetoinclude.txt");[/code]

My php is very shaky and these two pieces are giving me some problems. Thanks in advance for any assistance!

Edit: I suppose I asked this question inappropriately: I googled for the functions in both cases without any luck. If no one wishes to answer the first one because it's technically writing a script, that's perfectly understandable. However, if it's possible to find out how to properly define a variable as the contents of a text file, that would be spectacular.

Share this post

Link to post
Share on other sites
you will have to read the contents of the file with file_get_contents in order to use the contents as a variable (if you have older versions of php then you will need fopen, fread and fclose - read the manual on file_get_contents).

imply including a file means that file is trated as part of the script (note php automatically breaks out so if it were a snippett of code you would need to start with <?php in the include file!).

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.