note 22842 added to function.parse-str

From: Date: Tue, 02 Jul 2002 01:47:45 +0000
Subject: note 22842 added to function.parse-str
Groups: php.notes 
Request: Send a blank email to php-notes+get-32486@lists.php.net to get a copy of this message
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; -- http://www.php.net/manual/en/function.parse-str.php http://master.php.net/manage/user-notes.php?action=edit+22842 http://master.php.net/manage/user-notes.php?action=delete+22842 http://master.php.net/manage/user-notes.php?action=reject+22842

« previous php.notes (#32486) next »