Re: Reading File into Array and Searching

From: Date: Tue, 15 Jan 2002 19:51:40 +0000
Subject: Re: Reading File into Array and Searching
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-80616@lists.php.net to get a copy of this message
On Wednesday 16 January 2002 03:21, Devin Atencio wrote: > Dear Users, > > I basically want to do the following. I have file that contains everyone > that logs into > our mail server a day and then I want to basically load that file into an > array and then > search the array to find out how many times that person logged in and then > take > the last login and capture that information from the file. > > I have tried doing something like this but it doesn't seem to work: > > $fcontents = file("/tmp/popper.test"); > > while (list ($line_num, $line) = each ($fcontents)) { > $new_array[$line_num] = $line; > } > > $key = array_search("wasatch.com",$new_array); > print count($new_array)." matches found.\n"; > > Can anyone shed some light to help me? I'm using PHP 4.1.0 :) What doesn't work? Why doesn't it work? Do you get any error messages? What output do you get? As it stands your print statement will just print the number of lines in your file? The function you want is probably array_count_values(). hth -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk /* After Goliath's defeat, giants ceased to command respect. - Freeman Dyson */

« previous php.general (#80616) next »