Jump to content

Saving and loading an array


umekille78

Recommended Posts

Hi all!In a page Im working on Im saving alot of data to a file. And Im loading it back and changing it just to save it again. This is booring work when you use strings.My Idea is to use an array instead. But i dont know if you can save and load a whole array at onec. It would save me alot of trouble if one can do that.Can any one help me? Is it posible to save and load arrays? Or do I have to save it post for post and load it the same way?If it is possible can any one wright a small exampel to show how its done?Thanks :) /Per

Link to comment
Share on other sites

I have a file that looks something like this:ghi |789 | &*(abc | 123 | !@#def | 456 | $%^ghi |789 | &*(I then open the file and read it into a string.Then I break the string into an array (break it by line (\n) and by [space]|[space] )Then I search the 1st and 2nd set of data (abc, def, ghi) and (123, 456, 789)Then once that is found, I replace the data (Example replace 456 with 654)So then the data is replace and I have to write it back into the file...I write the replaced file back into the lineThen writes the lines back into a long stringlike this: abc | 123 | !@# \n def | 654 | $%^ \n ghi |789 | &*(Then I Clear the file and replace it with that above!------Does this sound like what you are looking for?

Link to comment
Share on other sites

Does this sound like what you are looking for?

Yes it sounds right but you are missing the point here. I asked if one can save an ARRAY to a file. Not how to make a array into a string and save the string. I already know how to do that.Im trying to optimice my program since its supose to have loads of trafic and alott of users handeling the same file.If its att all posible to save/load the array like one big "thing" it would improve the time a user holds the file ocupiced.Is this posible??/Per
Link to comment
Share on other sites

alright I figured out how to save an array to a separate file.in this example, the array will be outputed to a file named array.php (make sure you set it's permissions to 777). you will need to create the array.php file (completely blank).1b.php (name it whatever you want):EDIT: because this forum changes ASCII characters, here's a link to the code on my server: http://www.oneity-eight.roxr.com/misc/1b.txtI hope this helps you!Also note that I probably will not keep this file on my server forever, so if the link is down, and your interested in the code, PM me.

Edited by calvin182
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...