Page 1 of 1
Save multiple variables to text file with php
Posted: Wed Aug 05, 2009 10:58 am
by bocaj812
I need to be able to save form data to a .txt file with php.
I have three variables. $title, $description, and $content.
I need to save them to the .txt file, and be able to open that .txt file with php and use all three of the variables.
thanx,
Re: Save multiple variables to text file with php
Posted: Wed Aug 05, 2009 11:06 am
by Mark Baker
Then take a look at functions like fopen(), fwrite(), fclose() and fgets()
Re: Save multiple variables to text file with php
Posted: Wed Aug 05, 2009 11:11 am
by bocaj812
Mark Baker wrote:Then take a look at functions like fopen(), fwrite(), fclose() and fgets()
thanks
I looked at that, but it appears to only write one variable and i'm not sure if I could write multiple variable sand still use all three when i open the file up again.
Re: Save multiple variables to text file with php
Posted: Wed Aug 05, 2009 11:31 am
by Mark Baker
bocaj812 wrote:I looked at that, but it appears to only write one variable and i'm not sure if I could write multiple variable sand still use all three when i open the file up again.
Well, you could use three write statements, one for each variable, or a single write that wrote all three variables concatenated together.
Alternatively, you could store each of the three variables in an array, then serialise the array and write the result.... then unserialize it when you read it again.
Re: Save multiple variables to text file with php
Posted: Wed Aug 05, 2009 11:46 am
by bocaj812
Mark Baker wrote: you could store each of the three variables in an array, then serialise the array and write the result.... then unserialize it when you read it again.
thanks i'll try that
Re: Save multiple variables to text file with php
Posted: Wed Aug 05, 2009 12:54 pm
by bocaj812
I can put my variables into an array but now, how do i get them out?
Re: Save multiple variables to text file with php
Posted: Wed Aug 05, 2009 3:32 pm
by Jonah Bron
The fread() function. Then unserialize() the result like Mark said.