Hartley Posted July 6, 2006 Share Posted July 6, 2006 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 More sharing options...
ToonMariner Posted July 6, 2006 Share Posted July 6, 2006 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!). Link to comment https://forums.phpfreaks.com/topic/13822-problems-with-including-a-text-file/#findComment-53744 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.