Home > Backend Development > PHP Tutorial > Analysis of the difference between addslashes() and addclashes() functions in PHP

Analysis of the difference between addslashes() and addclashes() functions in PHP

WBOY
Release: 2016-07-25 08:58:18
Original
1161 people have browsed it
  1. //Add backslashes to specific characters in the string
  2. $str = "Hello, my name is John Adams.";
  3. echo $str;
  4. echo addcslashes($str, 'm');
  5. echo addcslashes($str,'J');
  6. ?>
Copy code

output:

  1. //Add backslash to predefined characters in string
  2. $str = "Who's John Adams?";
  3. echo $str . " This is not safe in a database query .
    ";
  4. echo addslashes($str) . " This is safe in a database query.";
  5. ?>
Copy code

output:

Who's John Adams? This is not safe in a database query. Who's John Adams? This is safe in a database query.

For the functions addslashes() and addclashes(), there are corresponding methods for removing backslashes, namely: stripcslashes function and stripslashes function. Friends who are interested can also study it.



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template