note 25065 added to function.parse-str

From: Date: Mon, 09 Sep 2002 20:33:06 +0000
Subject: note 25065 added to function.parse-str
Groups: php.notes 
Request: Send a blank email to php-notes+get-36405@lists.php.net to get a copy of this message
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. -- http://www.php.net/manual/en/function.parse-str.php http://master.php.net/manage/user-notes.php?action=edit+25065 http://master.php.net/manage/user-notes.php?action=delete+25065 http://master.php.net/manage/user-notes.php?action=reject+25065

« previous php.notes (#36405) next »