Re: array

From: Date: Wed, 22 Aug 2001 06:11:36 +0000
Subject: Re: array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-63859@lists.php.net to get a copy of this message
On Wed, 22 Aug 2001 15:34, Chris Herring wrote: > I'm trying to get an array to read the text from a file, and so far it > isn't working. If you can help me, respond. > > <snippet> > $fp = fopen ("./file.txt", "r"); > $text = array ($fp); > sort ($text); > reset ($text); > while (list ($key, $val) = each ($text)) { > echo "[".$key."] ".$val; > echo "<br>"; > } > fclose ($fp); > </snippet> > > Currently all that does is print out "[0] Resource id #1" > Any help is GREATLY appreciated. Thanks in advance. Well, $fp is not the contents of the file, but just a pointer. What you really want is file() $text = file('./file.txt'); will give you an array $file, where each element is a line in the file, with the newline attached. To do the same thing after fopen()ing the file you would need to use fgets() or fread(). The examples in the docs will be a bit more enlightening. -- David Robley Techno-JoaT, Web Maintainer, Mail List Admin, etc CENTRE FOR INJURY STUDIES Flinders University, SOUTH AUSTRALIA A camel is a horse planned by committee.

« previous php.general (#63859) next »