note 75733 added to function.serialize

From: Date: Wed, 13 Jun 2007 17:22:46 +0000
Subject: note 75733 added to function.serialize
Groups: php.notes 
Request: Send a blank email to php-notes+get-127454@lists.php.net to get a copy of this message
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); ---- Server IP: 69.39.81.135 Probable Submitter: 71.71.213.126 ---- Manual Page -- http://www.php.net/manual/en/function.serialize.php Edit -- https://master.php.net/note/edit/75733 Del: integrated -- https://master.php.net/note/delete/75733/integrated Del: useless -- https://master.php.net/note/delete/75733/useless Del: bad code -- https://master.php.net/note/delete/75733/bad+code Del: spam -- https://master.php.net/note/delete/75733/spam Del: non-english -- https://master.php.net/note/delete/75733/non-english Del: in docs -- https://master.php.net/note/delete/75733/in+docs Del: other reasons-- https://master.php.net/note/delete/75733 Reject -- https://master.php.net/note/reject/75733 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#127454) next »