note 25065 deleted from function.parse-str by tomsommer

From: Date: Tue, 31 Aug 2004 18:09:05 +0000
Subject: note 25065 deleted from function.parse-str by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-75759@lists.php.net to get a copy of this message
Note Submitter: kumar at chicagomodular dot com ---- [Editor's note: extract() and assignment to $GLOBALS should also work] if you need to use parse_str in the scope of a function, this is the only way I have found to globalize the parsed variables: function globalizeVarstring($varstring) { parse_str($varstring,$buff); foreach($buff as $variable => $contents) { $parse = 'global $'.$variable.'; '; $parse .= '$'.$variable.' = '; if(is_array($contents)) { ob_start(); var_export($contents); $parse .= ob_get_contents(); ob_end_clean(); } elseif(is_string($contents)) { $parse .= '"'.$contents.'"'; } else { $parse .= $contents; } $parse .= ';'; eval($parse); } return TRUE; } globalizeVarstring(str_replace("\n",""," ex[image][action]=finish&ex[id]=12& ex[image][1][title]=some scrolling image& ex[image][1][type]=scrolling& ex[image][2][title]=the main image ...& ex[image][2][type]=main& string=something")); if there is an easier way that would be nice.

« previous php.notes (#75759) next »