RE: [PHP] Creating an array with a file
| From: | Scott | Date: | Tue, 12 Feb 2002 01:00:06 +0000 |
| Subject: | RE: [PHP] Creating an array with a file | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-84200@lists.php.net to get a copy of this message | ||
I am seeking some thoughts on if this is the way I should tackle this
problem. I have two files, both of them tab delimited text files that I
need to combine and then output a new file.
My idea was to put both files in an array, calling the fields I need,
i.e. $field[0], $field[1] and so on. I need to loop through the entire
file and output on each loop.
My concern is the overhead by creating the array's. Any thoughts.
Thanks,
-Scott
-----Original Message-----
From: Paul Roberts [mailto:roberts_paul@bigfoot.com]
Sent: Sunday, February 10, 2002 2:35 PM
To: Scott
Subject: Re: [PHP] Creating an array with a file
try this, you need to get the line then explode that, fopen just returns
a file handle.
$file = fopen("oldfile.txt", "r");
while (!feof ($fd)) {
$lines = fgets($file, 4096)
$newfields = explode("\t", $lines);
echo $newfields[0]."<br>";
}
Paul Roberts
roberts_paul@bigfoot.com
++++++++++++++++++++++++
----- Original Message -----
From: "Scott" <scott@scottah.com>
To: <php-general@lists.php.net>
Sent: Monday, February 11, 2002 5:32 PM
Subject: [PHP] Creating an array with a file
> Hi All,
>
> I am trying to create an array from a text file that I will process
and
> rewrite in a new format. My question is, is it possible to read the
> file
> in one line at a time and then separate the tab-delimited fields and
> finally rewrite the new file?
>
> The fields are tab delimited and here is what I have attempted in
code:
>
> $lines = fopen("oldfile.txt", "r");
> $newfields = explode("\t", $lines);
> echo $newquotes[0];
>
> I get a Resource ID #1 when I echo the line.
>
> Thanks,
>
> -Scott
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>