PHP post get traditional, Japanese, Korean automatically add backslash problem

Source: Internet
Author: User

Do some two development projects, database, file encoding can not be large-scale modification, such as two times to develop a Japanese system, encoding is ja16sjis,$_post or $_get information if "Application", the information will become "Shen", more than a backslash!

Put out the solution first, add the following code where needed or in the configuration file

if (GET_MAGIC_QUOTES_GPC ()) {
function Stripslashes_deep ($value)
{
$value = Is_array ($value)?
Array_map (' Stripslashes_deep ', $value):
Stripslashes ($value);
return $value;
}
$_post = Array_map (' Stripslashes_deep ', $_post);
$_get = Array_map (' Stripslashes_deep ', $_get);
$_cookie = Array_map (' Stripslashes_deep ', $_cookie);
}

Network Collation Related:

Check, it seems can set php.ini in the Magic_quotes_runtime

In the PHP configuration file, there is a Boolean setting, that is magic_quotes_runtime, when it is opened,

Most of PHP's functions automatically add an overflow character to an externally introduced (including database or file) data with an inverse

Slash. Of course, if you repeat the multibyte backslash for the overflow character, there will be multiple backslashes in the string, so

Set up and detect with Set_magic_quotes_runtime () and Get_magic_quotes_runtime () php.ini

The Magic_quotes_runtime state in the file. To make your program work regardless of the server's settings

Perform. You can use Get_magic_quotes_runtime to detect the state of the setting at the beginning of the program to determine whether to manually process

, or use Set_magic_quotes_runtime (0) to turn off the setting at the beginning (or when no automatic escaping is required).

MAGIC_QUOTES_GPC set whether the "\" \ \ "\" in the data from GPC (Get,post,cookie) is automatically inverted

Line. System settings can be detected with GET_MAGIC_QUOTES_GPC (). If this setting is not turned on, you can use the

Addslashes () function is added, its function is to the database query statements and so on need to precede some characters with anti-

Slash. These characters are single quotation marks (\ '), double quotation marks (\ "), backslashes (\ \), and NUL (the NULL character).

The general usage is as follows;
if (!GET_MAGIC_QUOTES_GPC ())
{
Addslashes ($prot);
}

PHP post get traditional, Japanese, Korean automatically add backslash problem

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.