Deserialization can't print it's weird how to fix it.
Source: Internet
Author: User
Deserialization doesn't print well, it's weird.
$safe _faqs = ' A:4:{i:1;a:2:{s:8: "question"; S:37: "What is your favorite Web-building program?"; S:6: "Answer"; s:7: "Dedecms";} I:2;a:2:{s:8: "Question"; S:6: "1+11=?"; S:6: "Answer"; S:2: "12";} I:3;a:2:{s:8: "Question"; s:59: "Which sport in China is the most people to listen to sad, watching the pain?"; S:6: "Answer"; S:6: "Football";} I:4;a:2:{s:8: "Question"; s:29: ""; s:6: "Answer"; s:24: "Weaving dream Content Management System";}} ';
$safefaqs = unserialize ($safe _faqs);
Print_r ($safefaqs);
?>
Page is blank, why Ah, ask for guidance under
------Solution--------------------
Modify the file encoding to UTF-8.
------Solution--------------------
On the file UTF8 encoding, Chinese to convert it%xx%xx%xx such a
------Solution--------------------
LZ use Stripslashes () to try this before deserializing the serial number
I don't know if it's PHP automatically added \ this symbol.
------Solution--------------------
The key to solving this type of problem is knowing how serialization strings are composed
such as s:6: "Football";
s represents a string
6 indicates a length of 6 bytes
What's included in the double quotes is the content.
Because of the length indication, there is no ambiguity in the possible double quotes in the content
For this example, it is observed that football is two kanji and the length is 6, which means that this is serialized in the UTF-8 encoding environment.
You save the program as UTF-8 encoded, or $safe _faqs = iconv (' GBK ', ' utf-8 ', $safe _faqs);
Turn the code, all can be output normally
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