Jump to content

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.
Link to comment
https://forums.phpfreaks.com/topic/13822-problems-with-including-a-text-file/
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!).
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.