PHP escape usage _ PHP Tutorial

Source: Internet
Author: User
PHP escape usage details. When magic_quotes_gpc or magic_quotes_runtime of The Magic reference function of data in php is set to on, it is automatically added when the referenced data encounters single quotation marks, double quotation marks, and backslash. Magic_quotes_gpc or magic_quotes_runtime

When it is set to on, the single quotation mark (') and double quotation mark (') are applied to the referenced data, and the backslash (\) is automatically added to the backslash (\). This helps us to automatically translate the symbols to ensure the correct operation of data operations.
Differences between the two:

Magic_quotes_gpc
Scope of Application: WEB client server;
TIME: The request starts, for example, when the script is running.

Magic_quotes_runtime
Scope: obtained from the data read from the file, the exec () execution result, or the SQL query;
Time: each time a script accesses the data generated in the running state.

We can see that
The value of magic_quotes_gpc affects the data obtained through Get/Post/Cookies.
The value of magic_quotes_runtime will affect the data read from the file or the data queried from the database.

Several functions to be associated:
Set_magic_quotes_runtime ():
Set magic_quotes_runtime value. 0 = Close. 1 = open. the default status is disabled. you can use echo phpinfo () to view magic_quotes_runtime
Get_magic_quotes_gpc ():
View magic_quotes_gpc value. 0 = Close. 1 = open
Get_magic_quotes_runtime ():
View the value of magic_quotes_runtime. 0 = Close. 1 = open.
Note that the value of magic_quotes_gpc () cannot be set in the program.

Due to the setting of the two values, it may cause some confusion during programming or add an escape. in this case, you need to set and judge the values at the beginning of the program, or configure the values by default.
Both values are disabled. The escape part is executed by a program.

To ensure normal data insertion, addslashes is usually used for processing. stripslashes is used for data reading to remove the backslash.

Functions for converting similar characters in php
Add a backslash before the predefined characters specified by addslashes
Stripslashes delete the backslash added by the addslashes () function
Htmlspecialchars converts some predefined characters to HTML objects.
Htmlspecialchars_decode converts some predefined HTML entities into characters
Html_entity_decode () converts HTML objects into characters
Htmlentities () converts characters to HTML entities

When the quomagic_quotes_gpc or magic_quotes_runtime is set to on, it will automatically add the single quotation marks and double quotation marks for the data we reference and the backslash...

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.