Home  >  Article  >  Backend Development  >  How to add backslash before quotes in php (remove backslash in php)

How to add backslash before quotes in php (remove backslash in php)

WBOY
WBOYOriginal
2016-07-25 08:56:18827browse
  1. $str=$_POST["str"]; //Read the content of str and assign it to the $str variable
  2. if(get_magic_quotes_gpc()){ //If get_magic_quotes_gpc() is turned on
  3. $str=stripslashes($str); //Process the string
  4. }
Copy the code

The following introduces three methods to solve this problem:

1. Modify the PHP configuration file php.ini This method is only suitable if you have the right to manage the server. If you use virtual space, you can only use the last two methods. In the PHP configuration file php.ini, set magic_quotes_gpc, magic_quotes_runtime, and magic_quotes_sybase to off. As follows:

  1. if(get_magic_quotes_gpc()){
  2. function stripslashes_deep($value){
  3. $value=is_array($value)?array_map('stripslashes_deep',$value):stripslashes($value );
  4. return $value;
  5. }
  6. $_POST=array_map('stripslashes_deep',$_POST);
  7. $_GET=array_map('stripslashes_deep',$_GET);
  8. $_COOKIE=array_map('stripslashes_deep',$_COOKIE) ;
  9. $_REQUEST=array_map('stripslashes_deep',$_REQUEST);
  10. }
Copy code


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