note 19961 added to function.unserialize
| From: | michael at cannonbose dot com | Date: | Sat, 16 Mar 2002 20:17:45 +0000 |
| Subject: | note 19961 added to function.unserialize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27863@lists.php.net to get a copy of this message | ||
Here's a couple of helper functions to convert arrays to URL strings and back.
Special thanks to richard@richardhayes.net for the algorithms.
/**
* Array2URLString($array_in)
*
* Returns a serialized and encoded a array to be passed via the URL.
*
* @author Michael Cannon <michael@cannonbose.com>
* @param array $array_in
* @return string
*/
function Array2URLString($array_in) {
$ser = serialize($array_in);
$ser = urlencode($ser);
return $ser;
}
/**
* URLString2Array($url_string_in)
*
* Returns an array from a serialized and encoded URL string.
*
* @author Michael Cannon <michael@cannonbose.com>
* @param array $url_string_in
* @return string
*/
function URLString2Array($url_string_in) {
$ser1 = stripslashes($url_string_in);
$arr1 = urldecode($ser1);
$arr1 = unserialize($arr1);
return $arr1;
}
Example encoding:
$ser_from = Array2URLString($form);
// Sample URL creation
Header("Location: http://www.example.com/thankyou.php?ser_form="
. $ser_from);
Example decoding:
// URL looks like this:
// http://www.example.com/thankyou.php?ser_form=a%3A3...
// Retrieve ser_form
$body = URLString2Array($ser_form);
--
http://www.php.net/manual/en/function.unserialize.php
http://master.php.net/manage/user-notes.php?action=edit+19961
http://master.php.net/manage/user-notes.php?action=delete+19961
http://master.php.net/manage/user-notes.php?action=reject+19961