Re: Reading specific data from a .txt file into PHP
| From: | Pavel Kalian | Date: | Tue, 16 Jan 2001 15:20:31 +0000 |
| Subject: | Re: Reading specific data from a .txt file into PHP | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-34821@lists.php.net to get a copy of this message | ||
check the manual for fgets() function. then you can maybe explode() the
string using " " (space) as separator.
Pavel
----- Original Message -----
From: "James Holloway" <james@towntalk.co.uk>
To: <php-general@lists.php.net>
Sent: Tuesday, January 16, 2001 4:13 PM
Subject: Re: [PHP] Reading specific data from a .txt file into PHP
>
> Glen Scott <glen@designsolution.co.uk> wrote in message
> news:4.3.2.7.2.20010116151340.00b1d230@212.78.70.53...
> > James,
> >
> > The trouble is, that there are about 3000 cities in the text file. I'm
> > >assuming that I fill use fopen(); and fread(); to open and read the
> files,
> > >but does anyone know of a way of singling out one line (say:
> > >
> > >CYGL 161346Z 34004KT 15SM -SN BKN011 BKN030 RMK SF6SC1
> > >
> > >) from the whole text file? Like if a variable, $city = CYGL, is it
> > >possible to then go to that one line in the text file and read all the
> > >information from just one line? I'm pretty confident I could then
split
> the
> > >information up into readable variable using the split(); function :)
> >
> > Assuming the first field (i.e. CYGL) is unique, just read each line and
> > check using a regular expression whether it matches the city you
> > require. If it matches, you can stop reading the file and do whatever
you
> > need to do with the line.
>
> That's just it, I don't know how to 'read' each line and stop.... And the
> first field is unique.... Sorry to be such a dummy, I'm still very new to
> PHP, and have never really used Perl either ;)
>
> By 'using a regular expression', do you mean that something as simple as
an
> "if" statement might do the job?
>
> Can you help any further?
>
> Thanks for getting me this far.
>
> James.
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>