Why does php insert backslash while replacing double quotes

后端 未结 4 760
长发绾君心
长发绾君心 2021-01-21 21:10

I\'m wondering why php adds a backslash when i remove double quotes.




        
4条回答
  •  走了就别回头了
    2021-01-21 21:36

    It doesn't add them when you remove the slash, it automatically escapes them in the query string parameters when the magic_quotes_gpc directive is enabled (and it is, by default pre 5.30). It did this as a security precaution, so that the data could be safely used in a database query. You can disabled them by changing the setting in your php.ini file, see http://www.php.net/manual/en/security.magicquotes.disabling.php.

    You can also use stripslashes to remove them:

    $number = str_replace(array('"', "'"), '', stripslashes($number));
    

    An example use of stripslashes() is when the PHP directive magic_quotes_gpc is on (it's on by default), and you aren't inserting this data into a place (such as a database) that requires escaping. For example, if you're simply outputting data straight from an HTML form.

提交回复
热议问题