Re: PHP File Reading Problem

by "Kevin Haidl" <kevinh(at)actofmind.com>

 Date:  Wed, 5 Apr 2000 10:03:09 -0700
 To:  "Ilya Dubinsky" <ilya788(at)inter.net.il>
 Cc:  <hwg-languages(at)hwg.org>
 References:  net
  todo: View Thread, Original
I generated the file using DOS emacs and then uploaded as ASCII.  When I
tried to write my own fgets() I discovered that the line terminator in the
file is "\r".  O.K., so that's why fgets isn't working.  Why isn't PHP smart
like Perl and able to consider \r an alias for \n?  Why isn't ASCII being
received as \n?  What can I do about it?  I don't have control over who
uploads this data file, so if it's a DOS problem I must find another remedy.

> >My fgets() seems to be broken (or I've completely misunderstood the
> >documentation.)
> >
> >$datafile = fopen($sourcePath, "r");
> >while(!feof($datafile)) {
> >     $line = fgets($datafile, 32);
> >     echo("$line<br>");
> >}
> >
> >Specifically, the fgets() in the above code do not stop reading the file
> >when it encounters a newline.  The function always reads 31 characters.
> >This is distinctly inconvenient.  Anybody seen this before?  Any
suggestions
> >for a workaround?
>          The file you are reading -  is it in DOS text mode or Unix text
mode?
> Yours, Ilya.

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA