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.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]