note 59600 deleted from function.serialize by jacques

From: Date: Sun, 11 Dec 2005 20:05:52 +0000
Subject: note 59600 deleted from function.serialize by jacques
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-99967@lists.php.net to get a copy of this message
Note Submitter: none at none dot none ---- The only complaint I have about serializing, is that it will not save the variable name. To fix this, as well as add support for more then one variable/array, I chose to write this class: class SaveVar { function store($list) { $sl = explode("|", $list); for ($i = 0; $i < count($sl); $i++) { $varname = $sl[$i]; global $$varname; $thevar = $$varname; $serialized = serialize($thevar); $saved[$i] = base64_encode($varname)."@".base64_encode($serialized); } $data = implode("|", $saved); return($data); } function restore($stored) { $sv = explode("|", $stored); for ($i = 0; $i < count($sv); $i++) { $svp = $sv[$i]; list($name64, $value64) = explode("@", $svp); $name = base64_decode($name64); $value = base64_decode($value64); global $$name; $$name = unserialize($value); } } } ---- An example of using this class is as follows... ---- $arr1 = array("Hello", "World"); $arr2 = array("World", "Hello"); $sv = new SaveVar; $saved = $sv->store("arr1|arr2"); $arr1 = NULL; $arr2 = NULL; echo $saved; echo "<HR>"; $sv->restore($saved); print_r($arr1); echo "<BR>"; print_r($arr2); ---- I hope someone finds this useful... -Jestin S Larson

« previous php.notes (#99967) next »