PHP returns the function addslashes() that adds a backslash before a predefined character
黄舟
Release: 2023-03-16 21:40:02
Original
2197 people have browsed it
Example
Add a backslash before each double quote ("):
<?php
$str = addslashes('What does "yolo" mean?');
echo($str);
?>
Copy after login
Definition and usage
addslashes() function returns the predefined characters Strings preceded by a backslash:
Single quotation mark (')
Double quotation mark (")
Backslash. Bar (\)
NULL
Tip: This function can be used to prepare appropriate strings for strings stored in the database and database query statements.
Note: By default, the PHP instruction magic_quotes_gpc is on, automatically running addslashes() for all GET, POST and COOKIE data. Do not use addslashes() on strings that have been escaped by magic_quotes_gpc, as this will result in double escaping. When encountering this situation, you can
<?php
$str = "Who's Peter Griffin?";
echo $str . " This is not safe in a database query.<br>";
echo addslashes($str) . " This is safe in a database query.";
?>
The above is the detailed content of PHP returns the function addslashes() that adds a backslash before a predefined character. For more information, please follow other related articles on the PHP Chinese 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