PDA

View Full Version : PHP Templates - write to text files?



jingman
September 6th, 2003, 12:14 AM
Here's what I need to do:

Make a backend for a client that allows them to change some simple words in one of their web pages.

I want to do this with a form. When they submit it, I want the changes to occur on the site.

I've done a lot of reading, and as far as I can tell, I need to somehow write these variables to a file, and then use include() to get them into the final page. Is this correct?

So my problem is, I want to output all of these variables to a text file that php can read in all at once, so it will look something like:


$varToStore1 = "String Value1";
$varToStore2 = "String Value2";
$varToStore3 = "String Value3";

That way when I use include("thatTextFile.txt") in the final page, it will basically load those variables right?

What I can't figure out is how to write such a file with PHP. I know how to write files, append them, etc. But I don't know how to get the proper string output. Like how do you output quotes? PHP just freaks out on me.

If my way seems weird, it prolly is, so can you recommend a better way to do this template type thing? Thanks!

Jubba
September 6th, 2003, 01:37 AM
you don't include the text file, you open it for reading and then read the text file...



$file = "mytextfile.txt";
$fp = fopen($file, "r");
$data = fread($fp, 80000);

print $data;

fclose($fp);

jingman
September 6th, 2003, 01:45 AM
Well, I want to read in variables from a file that I have just written dynamically, I don't just want to read a text file and print the result.

I have solved the problem with some help. I needed to use escape characters for the quotes and '$' for variables, etc.

Everything is working fine now, thanks Jubba.