Yesterday with PHP made a read and write HTML document applet, local testing is normal but to the site found that when the submission is saved automatically in double quotation marks in front of a backslash "\", and every time you save a backslash, it is depressed.
Of course, do this just to participate in the electronic shopping district website to update, because too lazy to install CMS and blog program, directly with PHP online modification HTML Document to update the text bar.
From the Internet. Originally PHP program to prevent injection or overflow, through the PHP directive MAGIC_QUOTES_GPC automatically in double quotes, single quotes, backslashes, null before the backslash "\".
But in order to read and write HTML documents, we naturally have a lot of quotes and double quotes, this time we should remove the added backslash.
The default PHP directive MAGIC_QUOTES_GPC is on, which is open. You can then use the stripslashes () function to remove the auto-added backslash. The usage is: for example, the variable containing the string is $STR, then use the stripslashes () function to process the string: stripslashes ($STR), the result of the output is to remove the backslash.
So I took the read string content with the Stripslashes () function, that is, $str=stripslashes ($STR), and then save. After uploading the website is normal.
However, another problem arises because the local PHP directive MAGIC_QUOTES_GPC is off, and if this function is used, it will remove the normal backslash. This is not what we want.
The solution is to use the function GET_MAGIC_QUOTES_GPC () to detect, if it is open, then remove the backslash, if the state is closed, do not remove the backslash.
The program code is as follows:
$str=$_post["str"]; Read the contents of STR to the $STR variable if(get_magic_quotes_gpc())///If GET_MAGIC_QUOTES_GPC () is open {$str=stripslashes($str); The string is processed }
The modified program tests both locally and on the Web site as normal.
Why PHP adds backslashes before quotation marks and how PHP removes backslashes