Re: Beginner question?
| From: | jtjohnston | Date: | Fri, 21 Dec 2001 06:59:31 +0000 |
| Subject: | Re: Beginner question? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-78422@lists.php.net to get a copy of this message | ||
Michael,
$fp = fopen ("./users.txt", "r");
while (!feof ($fp)) {
$buffer = fgets($fp, 4096);
echo $buffer;
}
fclose($fp);
Ok. But $buffer is not an array, is it? Why/what is 4096? What is !feof ?
Can anyone show me how to split() each line and parse to see if $user exists?
Here's what I'm upto. I want to use users.txt as a user:password text database
file.
I want to read users.txt into an array.
I want to parse each line splitting for ":"
user:pass
john:help
michael:thanks
$fp = fopen ("./users.txt", "r");
while (!feof ($fp)) {
$buffer = fgets($fp, 4096);
echo $buffer;
}
fclose($fp);
$user = "john";
$num_fields = count($buffer);
for ($i = 0; $i < $num_fields; $i++)
{
if ?? = $user then echo ??
}
Can anyone show me how to split() each line and parse to see if $user exists?
> ><?php
> >$fp = fopen ("./info.txt", "r");
> >print $fp;
> >fclose($fp);
> >?>
> $fp is just a file pointer, not the actual contents of the file. You need
> to use fgets() (or something similar) to actually get the contents out.
> http://www.php.net/manual/en/function.fgets.php