note 22842 deleted from function.parse-str by nlopess

From: Date: Sat, 13 Mar 2004 21:34:14 +0000
Subject: note 22842 deleted from function.parse-str by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-66786@lists.php.net to get a copy of this message
Note Submitter: glyn@minimanga.com ---- Here's a little bit of code to parse the lines of a text file into a list of numbered variables. This may not be the most efficient example, but I'm a beginner, so forgive any obvious mistakes I make. It worked for me! The example assumes 5 lines of text, but you could take it as far as you wanted it to go. $fp = fopen("testing.txt", "r"); $contents = 1; // Start up the loop $id = 0; $varname = 'quote'; while ($contents) { $contents = fread($fp, 1); if ($contents == "\n") { $id++; $newvar = $varname.$id.'='.$output; // Creates variable/key to parse parse_str($newvar); // Parses our string into a variable $output = ''; // Clear the 'buffer' so there's not repetition } $output = $output.$contents; } fclose($fp); print $quote1; print $quote2; print $quote3; print $quote4; print $quote5;

« previous php.notes (#66786) next »