You could also do this:

$fp = fopen($filename, "r");
while(!feof($fp)) {
    $string = fgets($fp, 25); //25 specifies how many chars to read in
    //process string here
}
fclose($fp);

The above code has not been tested, but it should give you an idea.

One thing I have noticed is that reading an entire file into PHP's memory
can make PHP use a /lot/ of memory. The above method reads it 25 chars at
a time. You could also just use fgets($fp) and it would read until the end
of the line (depending on what verison of PHP you are using). See
$mirror.php.net/fgets for more info.

-Dash

Ginsberg's Theorem:
        (1) You can't win.
        (2) You can't break even.
        (3) You can't even quit the game.

Freeman's Commentary on Ginsberg's theorem:
        Every major philosophy that attempts to make life seem
        meaningful is based on the negation of one part of Ginsberg's
        Theorem.  To wit:

        (1) Capitalism is based on the assumption that you can win.
        (2) Socialism is based on the assumption that you can break
            even.
        (3) Mysticism is based on the assumption that you can quit the
            game.

On Wed, 15 Jan 2003, Nichols, Mark A. wrote:

> I always look in the manual first.  I guess I missed it.
>
> Thanks
>
>
> -----Original Message-----
> From: Mikey [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 15, 2003 10:42 AM
> To: [EMAIL PROTECTED]
> Subject: RE: [PHP-WIN] Reading in text file characters
>
> You could try using the substr() function, it will take any number of
> chars
> from any place in a string.  However, I think you could have found this
> had
> you been bothered to look in the manual first...
>
> HTH,
>
> Mikey
>
>
> > -----Original Message-----
> > From: Nichols, Mark A. [mailto:[EMAIL PROTECTED]]
> > Sent: 15 January 2003 15:17
> > To: [EMAIL PROTECTED]
> > Subject: [PHP-WIN] Reading in text file characters
> >
> >
> > The following code reads in a text file one line at a time.
> >
> >
> >
> > for ($k=0; $k<=count($readfile)-1; $k++) {
> >
> >             $fields = split("\t",$readfile[$k]);
> >
> >             echo nl2br("$fields[0]<br>");
> >
> >
> >
> > }
> >
> >
> >
> > The problem is that it seems to strip the empty spaces out.
> >
> >
> >
> > My text file is formatted by lengths.  I need to read the first 25
> > characters from the text file.  Then read 50 more... And so on.
> >
> >
> >
> > Can anyone give my the code for reading in a certain number of
> > characters from a text file.
> >
> >
> >
> > Thank you in advance.
> >
> >
>
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


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

Reply via email to