PHP/Utility Function/serialize
Saving Arrays
$array["a"] = "Foo";
$array["b"] = "Bar";
$array["c"] = "Baz";
$str = serialize($array);
$strenc = urlencode($str);
print $str . "\n";
print $strenc . "\n";
Saving Objects
<?
abstract class Dog {
public function __clone( ) {
echo "In dog clone\n";
}
}
class Poodle extends Dog {
public $Name;
public function __clone( ) {
echo "In poodle clone\n";
parent::__clone( );
}
}
$poppy = new Poodle("Poppy");
$safepoppy = urlencode(serialize($poppy));
?>
Serialization
<?php
$a= array("foo" => "testing", 0 => 10, 1 => "mystring");
echo serialize($a);
?>
Storing and Retrieving Objects
<?
class apple {
var $flavor="sweet";
}
$app = new apple();
$stored = serialize( $app );
print $stored;
?>