Home  >  Article  >  Backend Development  >  How to remove escaping in PHP

How to remove escaping in PHP

巴扎黑
巴扎黑Original
2016-11-24 14:34:482214browse

string addslashes (string str)

Returns a string with backslashes added in front of certain characters for database query statements, etc.

These characters are single quotes ('), double quotes ("), backslash (\) and NUL (NULL character)

stripslashes have the opposite effect. When processing mysql and GET and POST data, it is often necessary to modify the data. Escape quotes.

There are three settings in PHP that can automatically escape ' (single quote), " (double quote), \ (backslash) and NULL characters.

PHP calls it magic quotes. These three settings are magic_quotes_gpc which affect HTTP request data (GET, POST and COOKIE). Cannot be changed at runtime. The default value in PHP is on.

magic_quotes_runtime If turned on, most functions that obtain and return data from external sources, including databases and text files, will return backslash-escaped data. This option can be changed at runtime, and the default value in PHP is off.

magic_quotes_sybase If turned on, single quotes will be escaped using single quotes instead of backslashes. This option completely overrides magic_quotes_gpc. If both options are turned on at the same time, single quotes will be escaped into ". Double quotes, backslashes and NULL characters will not be escaped. Although it is convenient to automatically escape special symbols, this This will reduce program efficiency and make program portability cumbersome.

If you don’t know the server ini settings, you need to call get_magic_quotes_gpc(), get_magic_quotes_runtime() or ini_get() to detect the status.

Use. stripslashes remove escaping

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn