Knowledge Treasure: Introduce PHP variable serialization storage format _php Tutorial

Source: Internet
Author: User
PHP is still more commonly used, so I studied the PHP variable serialization, here to take out and share with you, I hope it is useful to everyone. Serialization is probably the form of converting some variables into a byte stream of strings, which is easier to transmit and store. Of course, off is the transfer of storage nothing, the key is to become a string of the form can be converted back, but also to maintain the structure of the original data.

Serialization is probably the form of converting some variables into a byte stream of strings, which is easier to transmit and store. Of course, off is the transfer of storage nothing, the key is to become a string of the form can be converted back, but also to maintain the structure of the original data. A function that has multiple serialization in PHP: Serialize (), which converts any variable value (except a resource variable) into a string, can save the string to a file, or register as a session, or use curl to simulate get/post to transfer variables, Achieve the effect of RPC. If you want to convert the serialized variable to PHP's original variable value, you can use the Unserialize () function.

Serialization of PHP variables

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

Integral type :

 
  
  
  1. $ var ;

Output: i:23;

floating point type :

 
  
  
  1. $ var 1.;

Output: d:1.229999999999999982236431605997495353221893310546875;

string :

 
  
  
  1. $ var "This is a string";
  2. Echo Serialize ($var);
  3. $ var "I am a variable";

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

Boolean type :

 
  
  
  1. $ var true;
  2. Echo Serialize ($var);
  3. $ var false;

Output: b:1;b:0;

After 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, the second: the partition, the variable length is optional, is in the string type, the other type is not, the last one is the variable value, Each serialized value is ";" As the end.


http://www.bkjia.com/PHPjc/446492.html www.bkjia.com true http://www.bkjia.com/PHPjc/446492.html techarticle PHP is still more commonly used, so I studied the PHP variable serialization, here to take out and share with you, I hope it is useful to everyone. Serialization is probably the conversion of some variables into ...

  • 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.