note 75733 deleted from function.serialize by aharvey

From: Date: Tue, 06 Nov 2012 02:11:16 +0000
Subject: note 75733 deleted from function.serialize by aharvey
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-191775@lists.php.net to get a copy of this message
Note Submitter: lacent at gmail dot com ---- i noticed the same problem related to quotes, but the person below had no code detailing it. i can only assume he wrote it to fix values, and not to fix the whole array, so heres 2 functions to handle encoding the array. function slw_serial ( $var = array(), $recur = FALSE ) { if ( $recur ) { foreach ( $var as $k => $v ) { if ( is_array($v) ) { $var[$k] = slw_serial($v, 1); } else { $var[$k] = base64_encode($v); } } return $var; } else { return serialize(slw_serial($var, 1)); } } function slw_unserial ( $var = FALSE, $recur = FALSE ) { if ( $recur ) { foreach ( $var as $k => $v ) { if ( is_array($v) ) { $var[$k] = slw_unserial($v, 1); } else { $var[$k] = base64_decode($v); } } return $var; } else { return slw_unserial(unserialize($var), 1); } } --------- USAGE: --------- $array = array(); $array[] = 'this "is a" test'; $array[] = array('pos'=>'test', 'name'=>'some "dude in" cali'); $array = slw_serial($array); echo $array . '<Br><br>'; $array = slw_unserial($array); echo print_r($array, 1);

« previous php.notes (#191775) next »