The words in the manual and some summary:
PHP function serialize () and unserialize () description and case. To change the serialized string back to PHP's value, use Unserialize (). Serialize () can handle any type except resource. You can even serialize () those arrays that contain pointers to their own references. The references in the array/object you are serialize () will also be stored.
Serialize () returns a string that contains a byte stream representing value that can be stored anywhere. This facilitates the storage or delivery of PHP values without losing their type and structure.
To change the serialized string back to PHP's value, use Unserialize (). Serialize () can handle any type except resource. You can even serialize () those arrays that contain pointers to their own references. The references in the array/object you are serialize () will also be stored.
When serializing an object, PHP will attempt to call the object's member function __sleep () before the sequence action. This allows the object to do any cleanup before it is serialized. Similarly, when you use Unserialize () to restore an object, the __wakeup () member function is called.
Note: In PHP 3, the object properties will be serialized, but the method will be lost. PHP 4 Breaks This limit and can store properties and methods at the same time. See the serialization Objects section of classes and objects for more information.
Serialize () and unserialize () are explained in the PHP manual as:
Serialize-generates a storable representation of a value
Serialize-produces a representation of a value that can be stored
Unserialize-creates a PHP value from a stored representation
unserialize-to create a PHP value from a stored representation
Serialize, translated to call "serial, make continuous", usually called it "serialization"
This function is very useful, especially with unserialize.
I think the more useful thing is to put the data into the database or record in the file when
Of course, this data must be more complex (not complex and need not serialize, I think at least an array), but also the database is not "index or primary key", of course, it is best that the database field in the system and any search program independent, Of course, after the serialize data is still able to search, because the specific data has not been encrypted or changed
Example: (Just talk about the object, others should be easy)
cperson.php
[PHP]
Class Person
{
Public $age;
function __construct ($age)
{
$this->age= $age;
}
Function Walk ()
{
echo "I ' m walking...!";
}
}
?>
Test0.php Save the object here
[HTML]
Session_Start ();
Include_once './cperson.php ';
$person =new Person (22);
$b =serialize ($person);
$_session["Object"]= $b;
?>
Test1.php Accessing objects
[PHP]
Session_Start ();
Include_once './cperson.php ';
$p =$_session[' object '];
$a =unserialize ($p);
$a->walk ();
Echo $a->age;
?>
http://www.bkjia.com/PHPjc/477998.html www.bkjia.com true http://www.bkjia.com/PHPjc/477998.html techarticle the words in the manual and some summary: PHP function serialize () and unserialize () description and case. To change the serialized string back to PHP's value, use Unserialize (). Serialize ( ...