note 75560 added to function.serialize
| From: | emailfire at gmail dot com | Date: | Tue, 05 Jun 2007 14:34:29 +0000 |
| Subject: | note 75560 added to function.serialize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-127232@lists.php.net to get a copy of this message | ||
Here is a function I wrote that replicates the serialize function. Its pretty accurate but there may
be a few bugs or something that I have overlooked:
<?php
function serial($value) {
if (is_string($value)) {
return 's:'.strlen($value).':"'.$value.'";';
}
elseif (is_int($value)) {
return 'i:'.$value.';';
}
elseif (is_bool($value)) {
return 'b:'.(($value == true) ? 1 : 0).';';
}
elseif (is_array($value)) {
$a = 'a:'.count($value).':{';
foreach ($value as $key => $val) $a .= serial($key) . serial($val);
$a .= '}';
return $a;
}
elseif (is_object($value) && $name = get_class($value)) {
$o =
'O:'.strlen($name).':"'.strtolower($name).'":'.count($value).':{';
foreach ($value as $key => $val) $o .= serial($key) . serial($val);
$o .= '}';
return $o;
}
else {
return 'N;';
}
}
?>
----
Server IP: 194.145.210.3
Probable Submitter: 195.137.51.111
----
Manual Page -- http://www.php.net/manual/en/function.serialize.php
Edit -- https://master.php.net/note/edit/75560
Del: integrated -- https://master.php.net/note/delete/75560/integrated
Del: useless -- https://master.php.net/note/delete/75560/useless
Del: bad code -- https://master.php.net/note/delete/75560/bad+code
Del: spam -- https://master.php.net/note/delete/75560/spam
Del: non-english -- https://master.php.net/note/delete/75560/non-english
Del: in docs -- https://master.php.net/note/delete/75560/in+docs
Del: other reasons-- https://master.php.net/note/delete/75560
Reject -- https://master.php.net/note/reject/75560
Search -- https://master.php.net/manage/user-notes.php