RE: [PHP] pulling data out of a text file

From: Date: Thu, 28 Dec 2000 04:22:31 +0000
Subject: RE: [PHP] pulling data out of a text file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-32039@lists.php.net to get a copy of this message
doing a "fopen()" returns only a pointer to the actual file, so you have to read one line from the file each time you enter your while loop. $row=explode(',',$fp); should be: $row=explode(',',$fgets($fp, 4096); where 4096 is the maximum amount of characters that can be on one line... the string will end when the end of the line is reached or when 4096 characters are reached or when the end of the file is reached. An alternative is to do a $file_array = file("userdata") which will return the entire content of the file into an array and then you can traverse the array... Might not be a good idea if your text file is many megabytes in size... -----Original Message----- From: Richard Kurth [mailto:rkurth@pacifier.com] Sent: Wednesday, December 27, 2000 23:15 To: Php Subject: [PHP] pulling data out of a text file I cannot seem to figure this out after many hours of looking at the list archives and playing with different things it still will not do what I what it to. I want it to fill the variables with what is in the userdata file. The userdata file looks like this newdomain,.com,Company,Firstname,Name,Street Adress 1,12345, Small Town,,,customer@somedomain.com,Pack1,no,no,no The script I am using looks like this so what am I doing wrong. $fp=fopen ("userdata","r")or die("unable to open file ($userdata)"); flock($fp, 2); //unless ($use_flock == 0); while (!feof ($fp)) { $row=explode(',',$fp); } $row[0]= $domain; $row[1]=$tld; $row[2]=$company; $row[3]=$firstname; $row[4]=$lastname; $row[5]=$address; $row[6]=$zip; $row[7]=$city; $row[8]=$telephone; $row[9]=$fax; $row[10]=$email; $row[11]=$package; $row[12]=$frontpage; $row[13]=$mysql; $row[14]=$change_registrar; -- 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 (#32039) next »