Re: Setting variables from a text file

From: Date: Wed, 14 Nov 2001 21:39:14 +0000
Subject: Re: Setting variables from a text file
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-74642@lists.php.net to get a copy of this message
I couldn't get this to work. Here is my complete script: <? function WriteToFile ($URL, $Description) { $file = "bonzai.txt"; $open = fopen ($file, "a"); if ($open) { fwrite ($open, "$URL\t$Description\n"); fclose ($open); $Worked = TRUE ; } else { $Worked = FALSE; } return $Worked; } function ReadFromFile() { $file = "bonzai.txt"; $open = fopen ($file, "r"); if ($open) { print ("URLs currently listed in the data file:<P>\n"); $data = file ($file); for ($n = 0; $n < count($data); $n++) { $GetLine = explode("|", $data[$n]); print ("$GetLine[0]<p>\n"); } fclose ($open); print ("<hr><P>\n"); } else { print ("Unable to read from bonzai.txt!<BR>\n"); } } ReadFromFile(); ?> It gives me some error. I'm still pretty new to php, so I still need to learn all of this. Regards Rudi Ahlers ----- Original Message ----- From: "Jeff Lewis" <jeff@hyrum.net> To: "Rudi Ahlers" <kopspier@bigfoot.com>; "PHP General" <php-general@lists.php.net> Sent: Wednesday, November 14, 2001 10:11 PM Subject: Re: [PHP] Setting variables from a text file > Someone may have a better way but you can read each line (assuming the file > uses \n for a new record) and use: > > arrayname = explode("|",$variable_holding_line_from_file); > > Then you can do assign the variables as such: > > $name = $arrayname[0]; etc > > Could be a better way from the list :) > > Jeff > ----- Original Message ----- > From: "Rudi Ahlers" <kopspier@bigfoot.com> > To: "PHP General" <php-general@lists.php.net> > Sent: Wednesday, November 14, 2001 3:08 PM > Subject: [PHP] Setting variables from a text file > > > > Hi > > > > Say I have a text file, separated by "|" ( a pipe). Now, I want to extract > > that info, in the form of variables. I can extract and display the info in > > the text files, but that's not what I want. I want to be able to tell it > > that the first entry should be variable1, the second entry should be > > variable2, etc. I add the info into the file with a script, that always > adds > > variable1 into field one, variable2 into field2, etc. These variables are > > taken from a form. Now, I need to pass those variables onto another > script, > > but I need to be able to extract them. Can anyone help me with this > please? > > Thank you > > > > Rudi Ahlers > > > > > > > > -- > > 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 > > > > > > > > > -- > 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 (#74642) next »