note 47809 added to function.serialize
| From: | php-general at lists dot php dot net | Date: | Wed, 01 Dec 2004 09:30:40 +0000 |
| Subject: | note 47809 added to function.serialize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81215@lists.php.net to get a copy of this message | ||
This is just a modification of what Alan Reddan (areddan at silverarm dot ie) posted below.
I figured it would be faster than walking an array, and it works wonderfully with cookies
<?php
$data[qwerty] = "blah";
$data[1][a] = "1aa";
$data[2][b] = "2bb";
$data[3][c] = ";;;;;;";
$data[name][first] = "Bob";
$data[name][last] = "Jones";
$data[val] = "This is a real long test string, to see how well the compression works!";
//To Serialise Call :
$string = gzcompress(serialize($data), 9);
setcookie("my_var", $string, time()+60*60*24*60, '/');
//print "String: $string\n<br>"; //uncomment to see serialized array
//To Unserialize Call
if (isset($_COOKIE[my_var])) {
$array = unserialize(gzuncompress($_COOKIE[my_var]));
echo "<pre>";
print_r($array);
echo "</pre>";
}
?>
you can replace gzcompress with base64_encode and gzuncompress with base64_decode to have a similar
experience
Alan, thanks for the tip though, it got me where I wanted to be!
----
Manual Page -- http://www.php.net/manual/en/function.serialize.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47809
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47809&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47809&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47809&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47809&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47809&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47809&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47809&report=yes
Search -- http://master.php.net/manage/user-notes.php