Re[2]: [PHP] pulling data out of a text file

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

« previous php.general (#32040) next »