PHP for security, so introduced a MAGIC_QUOTES_GPC = on function, you can directly put single quotation marks into the database without any processing, then for off, you need to consider the problem of single quotes, rather than blindly trust the operating environment.
When MAGIC_QUOTES_GPC = on, the data processed using addslashes () is saved in the database in the form of \ ', and if it is directly output at this time, it will be found to be more than what you expect, so Stripslashes () , it can remove the \ (different from str_replace ("\", "", $Str)).
When MAGIC_QUOTES_GPC = Off , the data processed using addslashes () will be saved in the database as ' form ', without the problem of the above mentioned \ Addslashes () The effect of inserting data is not wrong, if output directly at this time, the data is normal. No need to use stripslashes ().
Addslashes () and stripslashes () are exactly the opposite, Direct Memory: addslashes () Add a \,stripslashes () to a \
So when do you use it?
Simply put:
When MAGIC_QUOTES_GPC = ON, the system automatically handles issues such as single quotes, with no addslashes () and stripslashes (), but if the data is added with Addslashes (), Then the data must be displayed stripslashes ()
When MAGIC_QUOTES_GPC = off, the system does not handle problems such as single quotes, so you must use Addslashes () when inserting data, and you do not need to use stripslashes () when displaying data.
Since there is analysis, what to do when the program? Depending on the above two conditions, it is possible to:
Regardless of whether MAGIC_QUOTES_GPC is on or off, we use addslashes () when we add data, and when on, we must use Stripslashes (), which is not stripslashes () when off.
How do I tell if it is on or off? Use GET_MAGIC_QUOTES_GPC ().
The last example:
Code
Submit data, or variable preparation:
$Content =addslashes ("This is data, whether there is a single quote or a variable");
Inserting data into the database, omitting the code
Start displaying data
$Content = "Data read from the database";
if (GET_MAGIC_QUOTES_GPC ()) {
$Content =stripslashes ($Content);
}
Echo $Content;
The difference between PHP stripslashes and addslashes