Sometimes we run into such data (strings)
1 a:3:{i:0;s:44: "/uploads/images/2017-07-21/5971a9a08ad57.png"; i:1;s:44: "/uploads/images/2017-07-21/ 5971a9a5eb19c.png "; i:2;s:44:"/uploads/images/2017-07-21/5971a9a99e7df.png ";}
It would be quite troublesome to face such strings in order to split the strings with separators in the usual way, in fact, this string is a string that is serialized after the serialize () function. The demo is as follows:
1. Write an array
1 $ASD = Array ('/uploads/images/2017-07-21/5971a9a08ad57.png ', '/uploads/images/2017-07-21/5971a9a08ad57.png ', '/ Uploads/images/2017-07-21/5971a9a08ad57.png ');
2. Use the serialize () function to serialize the array, and we'll get the kind of string we came across at the beginning.
1 Dump (serialize ($ASD));
3. Re-use the unserialize () function to convert the serialized string back to the value of PHP
1 $qwe = serialize ($ASD); 2 Dump (Unserialize ($qwe));
Note:
Serialize--produces a representation of a value that can be stored
Serialize () returns a string that contains the value byte stream represented and 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.
Unserialize--Create a PHP value from a stored representation
Unserialize () operates on a single serialized variable and converts it back to the value of PHP. Returns the converted value, which can be an integer, float, string, array, or object. Returns FALSEif the passed string is not serializable.
About the use of serialize () and unserialize () in PHP (that is, about the conversion of values in PHP to stored representations)