note 13074 deleted from function.serialize by aharvey

From: Date: Tue, 06 Nov 2012 02:01:29 +0000
Subject: note 13074 deleted from function.serialize by aharvey
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-191732@lists.php.net to get a copy of this message
Note Submitter: sbarnum at mac dot com ---- If you're having trouble with serialized strings, try this function. Pass it the name of an array whose value you want to include in hidden form inputs, a url, or session variable. Works with strings or multidimensional arrays. <?php ////////////////////////////////////////////// // propogate v0.8 by sbarnum // method can be 'form' or 'url' or 'session' ////////////////////////////////////////////// function propogate ($arrayName, $method='form', $arrayData=''){ if($arrayData){ // custom values passed to array, use these instead of globals ${$arrayName} = $arrayData; }else{ // use global values global ${$arrayName}; } if ($method == "session"){ session_register(${$arrayName}); return TRUE; } @reset(${$arrayName}); while (list($key,$value)=@each(${$arrayName})){ if (is_array($value)){ $subArrayName = $arrayName . "[" . $key . "]"; $html .= propogate ($subArrayName, $method, $value); }else{ switch ($method){ case "form": $html .= "<INPUT type='hidden' name='".$arrayName."[".$key."]' value='".htmlspecialchars($value)."'>\n"; break; case "url": $html .= "&".$arrayName."[".$key."]=" . urlencode($value); break; } } } return $html; } ?>

« previous php.notes (#191732) next »