Php array conversion string function. I used thinkphp and json_encode to save Chinese characters. the backslash disappears from the php array conversion string function. I used thinkphp and json_encode to save Chinese characters and the backslash disappears.
This is the original
[{"Title": "\ u5173 \ u6ce8 \ u65f6 \ u56de \ u590d", "url": "\/index. php? G = User ***** "}]
This is the result.
[{"Title": "u5173u6ce8u65f6u56deu590d", "url": "\/index. php? G = User ***** "}]
It is Chinese. it is processed using json_decode. if it is saved to the database, there will be no backslash,
Php version 5.2 and apache 2.2
I remember there is a variable type that can be saved, array conversion string, forget what it is called
Reply to discussion (solution)
Split
Serialize ($ array );
Unserialize ($ array );
I got a surprise.
Is Thinkphp a problem?
Directly using php's json_encode will not have a backslash.
Echo'
'; $ Arr = array ('title' => 'reply upon followed', 'URL' => '/index. php? G = User *** '); $ str = json_encode ($ arr); // echo $ str .'
'; Echo'';print_r(json_decode($str,true));echo '
';
[{"Title": "\ u5173 \ u6ce8 \ u65f6 \ u56de \ u590d", "url": "\/index. php? G = User ***** "}]
Array
(
[0] => Array
(
[Title] => reply when paying attention
[Url] =>/index. php? G = User ****
)
)
It should be the cause of the environment, and the slash is processed.
Check whether there is any processing such as stripslashes on the data, before saving it to the database.
Congratulations!
Check whether there is any processing such as stripslashes on the data, before saving it to the database.
Not clear. it should be handled,
Where can I set it?
I used json_decode to have a backslash, and it was no longer saved to the database,
It's okay to upload the server locally. the configuration is the same.
Local php 5.5
Php 5.2 Server,
Use the serialize function instead,
Returns a string. the array variable type is retained and remains unchanged.
Is Thinkphp a problem?
Directly using php's json_encode will not have a backslash.
Echo'
'; $ Arr = array ('title' => 'reply upon followed', 'URL' => '/index. php? G = User *** '); $ str = json_encode ($ arr); // echo $ str .'
'; Echo'';print_r(json_decode($str,true));echo '
';
[{"Title": "\ u5173 \ u6ce8 \ u65f6 \ u56de \ u590d", "url": "\/index. php? G = User ***** "}]
Array
(
[0] => Array
(
[Title] => reply when paying attention
[Url] =>/index. php? G = User ****
)
)
It seems to be a thinkphp problem. after saving, there will be no more, $ db-> save (json );
Point usage
Save is saved to the database. do you need to escape \ in \ u5173 \ u6ce8 \ u65f6 \ u56de \ u590d? Will TP do it for you?
Save is saved to the database. do you need to escape \ in \ u5173 \ u6ce8 \ u65f6 \ u56de \ u590d? Will TP do it for you?
You understand. do you need this?
Str_replace ("/\/", "\\\\", json)
Is it necessary to escape all data written to the database?
Yes. Special characters must be escaped when writing data to the database.
Yes. Special characters must be escaped when writing data to the database.
Well, thank you. I used to use asp. I can write the values in the variables to the database.
Thank you for closing the post.
, Json_encode (array (); // The backslash that is written to the database disappears and must be escaped.
Asp \ is not a special character, but 'must be escaped