Hi Richard:

On Fri, May 24, 2002 at 02:42:59PM +0100, Meredith-Wilks, Richard wrote:

[NOTE:  Read throuhg the whole thing before commenting... --Dan]

>     set_time_limit(200);
>     $datafile = fopen ("text.txt", "r");
>     while (!feof ($datafile)) {
>       $array = fgets($datafile, 1000000);

fgets() produces a string, but you're saying it's an array.
If you want to fill an array, do this: 
       $array[] = fgets($datafile, 1000000);

>       if (trim($array)) {

Trim() on an array???  NAY!

>         $count = count(explode($Seper, $array));

Your code doesn't show that $Seper has been set to anything.

You run count on the array itslef, not the explode of array.  OH!  
Are you trying to take a line that's delimited by a special character 
and count the number of "fields" in the line?  In that case, back up.
Use fgetcsv (http://www.php.net/manual/en/function.fgetcsv.php):

       $array = fgets($datafile, 1000000, $Seper);
       $count = count($array);

Of course, you realize, the way this is set up makes the "echo $count"  
at the end only show the $count from the last line.  To get the total 
from the whole file, do this

       $count += count($array);

>       } // end if $array
>     } // end while
>     fclose ($datafile);
>     echo $count;

Also, you mentioned that the file is large.  You may need to bump up the 

Now, if my later observation is correct about what you're trying to do,
perhaps this is a simpler way to do what you're trying to do:

   $array = file('./text.txt');
   $content = implode('', $array);
   echo substr_count($content, $Seper);



               PHP classes that make web design easier
        SQL Solution  |   Layout Solution   |  Form Solution
    sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY     v: 718-854-0335     f: 718-854-0409

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to