PHP/Utility Function/serialize
Saving Arrays
<source lang="html4strict">
$array["a"] = "Foo";
$array["b"] = "Bar"; $array["c"] = "Baz"; $str = serialize($array); $strenc = urlencode($str); print $str . "\n"; print $strenc . "\n"; </source>
Saving Objects
<source lang="html4strict">
<?
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));
?>
</source>
Serialization
<source lang="html4strict">
<?php
$a= array("foo" => "testing", 0 => 10, 1 => "mystring"); echo serialize($a);
?>
</source>
Storing and Retrieving Objects
<source lang="html4strict">
<? class apple {
var $flavor="sweet";
} $app = new apple(); $stored = serialize( $app ); print $stored; ?>
</source>