Re: Saving an array as a file
| From: | Michael Kimsal | Date: | Wed, 01 Nov 2000 22:03:33 +0000 |
| Subject: | Re: Saving an array as a file | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-23257@lists.php.net to get a copy of this message | ||
I may not be understanding exactly what you're looking to do.
You have an array that you want to save to disk, right?
Is it for storage only, or does it need to be readable/parseable
by a person or another process?
If it's for storage only, use serialize/unserialize
$x = serialize($arrayname);
echo $x; // neat bunch of stuff here
$arrayname = unserialize($x);
Does this help at all?
Jeff Demel wrote:
> Okay, here's my last dumb newbie question for today - maybe.
>
> I see how to use file() to open a text file as an array of strings with each
> line an array element. That's great. So I make my changes with whatever
> code to one or more array elements. Now, um, what do I do to save the
> changes back to the file?
>
> Example (not exactly what I'm really doing, but way simplified for clarity):
>
> //open file as an array
> $arrTextFile = file("test.txt");
> //modify array
> $arrText[0] = ereg_replace("this","that",$arrText[0]);
> $arrText[1] = ereg_replace("this other","that other",$arrText[1]);
> //save modified array back to test.txt file
> ??so what goes here??
>
> Maybe there's a better way to do this, I don't know. But I need to find a
> way to 1)find a specific line in a file (by matching a string value), modify
> a different portion of that line only - replacing part of the string with
> something else, and then saving the file.
>
> TIA
>
> -Jeff
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
==========================
Michael Kimsal
http://www.tapinternet.com
734-480-9961