Knowledge Book: Introduction to PHP variable serialized storage format_php tutorial

Source: Internet
Author: User
Knowledge Book: describes the serialized storage format of PHP variables. PHP is still quite common, so I have studied the serialization of PHP variables. here I will share it with you and hope it will be useful to you. Serialization is usually used to convert some variables into PHP, so I have studied the serialization of PHP variables. here I will share with you, hoping to be useful to you. Serialization is probably the form of converting some variables into byte streams of strings, which is easier to transmit and store. Of course, there is nothing to do with data transmission and storage. The key is that data can be converted back in the form of strings, and the original data structure can be maintained.

Serialization is probably the form of converting some variables into byte streams of strings, which is easier to transmit and store. Of course, there is nothing to do with data transmission and storage. The key is that data can be converted back in the form of strings, and the original data structure can be maintained. There is a multi-serialized processing function in PHP: serialize (), which converts any variable value (except the resource variable) into a string and saves the string to the file, you can also register as a Session, or use curl to simulate GET/POST to transmit variables to achieve RPC. If you want to convert a serialized variable to the original PHP variable value, you can use the unserialize () function.

Serialization of PHP variables

Let's give a simple example to illustrate the serialization of PHP variables and its storage format.

Integer:

 
 
  1. $var = 23;
  2. echo serialize($var);

Output: I: 23;

Floating point type:

 
 
  1. $var = 1.23;
  2. echo serialize($var);

Output: d: 1.229999999999999982236431605997495353221893310546875;

String:

 
 
  1. $Var="This is a string";
  2. Echo serialize ($ var );
  3. $Var="I am a variable";
  4. Echo serialize ($ var );

Output: s: 16: "This is a string"; s: 8: "I am a variable ";

Boolean:

 
 
  1. $var = true;
  2. echo serialize($var);
  3. $var = false;
  4. echo serialize($var);

Output: B: 1; B: 0;

After the serialization of these basic types, it is clear that the storage format after serialization is: variable type: [variable length:] Variable value; that is, the first character represents the variable type, second: it indicates Segmentation. the variable length is optional, that is, it is in the string type, other types do not exist, and the last one is the variable value. each serialized value is "; "As the end.


Bytes. Serialization is probably to convert some variables...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.