Re: Reading specific data from a .txt file into PHP

From: Date: Tue, 16 Jan 2001 15:25:23 +0000
Subject: Re: Reading specific data from a .txt file into PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-34824@lists.php.net to get a copy of this message
Another good way to do that is to load the file in the database. The cities are a constant, and you can have them loaded in the database by a script that check if they exist, if not create a new row with the new city; if exist you update the data only... Because if each time that a user goes to a page and this script check in the text for a specific city, it would be very slow... it would be easier, in my point of view, that the same script that grab the file from the server also update the data in the database table. This will give you more power like, the time that was updated, number of times per day and etc, that you can show to your users. Have fun, Rom ----- Original Message ----- From: Glen Scott <glen@designsolution.co.uk> To: James Holloway <james@towntalk.co.uk>; <php-general@lists.php.net> Sent: Tuesday, January 16, 2001 10:15 AM Subject: Re: [PHP] Reading specific data from a .txt file into PHP 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. Regards, Glen ----------------------------------------------------- Design Solution Limited t: +44 (0)1502 513008 f: +44 (0)1502 588622 e: info@designsolution.co.uk w: http://www.designsolution.co.uk Nouvotech House, Harbour Road, Oulton Broad, Suffolk, NR32 3LZ, UK ----------------------------------------------------- -- 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

« previous php.general (#34824) next »