PHP output strings with many special characters

Source: Internet
Author: User
PHP outputs strings with many special characters. if you want to use echo to output the following string: a: 4: {s: 8: & quot; collects & quot; a: 0: {} s: 8: & quot; comments & quot; a: 0: {} echo 'A: 4: {s: 8: & quot; coll PHP output strings with many special characters
Output the following string using echo:
A: 4: {s: 8: "collects"; a: 0: {} s: 8: "comments"; a: 0 :{}

Echo 'A: 4: {s: 8: "collects"; a: 0: {} s: 8: "comments"; a: 0 :{}';
This is definitely not the case.

Special characters must be processed one by one, because there are more than one output string, which is troublesome ,,

If you have tools or software that are not easy to use, you can directly input a string to generate code directly under echo.



------ Solution --------------------
Echo < A: 4: {s: 8: "collects"; a: 0: {} s: 8: "comments"; a: 0: {}. More information
EOF;

------ Solution --------------------
Serialization?
PHP code
Unserialize-create a PHP value description from a stored representation mixed unserialize (string $ str [, string $ callback]) unserialize () to operate on a single serialized variable, convert it back to the PHP value. The returned value is the converted value, which can be integer, float, string, array, or object. If the passed string cannot be deserialized, FALSE is returned. Note: If the unserialize_callback_func command needs to instantiate an undefined class during deserialization, you can set a callback function for calling (to avoid the incomplete object "_ PHP_Incomplete_Class "). You can use php. ini, ini_set (), or. htaccess to define 'unserialize _ callback_func '. It is called every time an undefined class is instantiated. To disable this feature, you only need to leave this setting empty. Note that the unserialize_callback_func command is provided from PHP 4.2.0. Note: The callback parameter is added in PHP 4.2.0. if the deserialized variable is an object, after successfully re-constructing the object, PHP automatically tries to call the _ wakeup () member function (if any ). Example #1 unserialize_callback_func Example
  Note: in PHP 3, the method is not saved when an object is deserialized. PHP 4 breaks this restriction and saves the attributes and methods. For more information, see the serialization object section of the class and object. Example #2 unserialize () Example
  See serialize (). Serialize-generate a representation of a stored value description string serialize (mixed $ value) serialize () returns a string that contains a byte stream that represents the value and can be stored anywhere. This facilitates storing or passing PHP values without losing their types and structures. To change serialized strings back to PHP values, use unserialize (). Serialize () can process any type other than resource. Even serialize () contains arrays that point to its own reference. References in arrays/objects of serialize () will also be stored. When an object is serialized, PHP tries to call the member function _ sleep () of the object before the sequential action (). This allows objects to be cleared before being serialized. Similarly, when unserialize () is used to restore an object, the _ wakeup () member function is called. Note: in PHP 3, object attributes will be serialized, but methods will be lost. PHP 4 breaks this restriction and can store attributes and methods at the same time. For more information, see the serialization object section of the class and object. Example #1 serialize () Example
  

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.