php method to escape double quotes: first create a PHP sample file; then add backlash before each double quote through the "addslashes('Shanghai is the "biggest" city in China.');" method Just use a slash to escape the string.
The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer.
addslashes — Quote (escape) a string using backslashes; the
addslashes() function returns a string with a backslash added before a predefined character.
The predefined characters are:
单引号(') 双引号(") 反斜杠(\) NULL
Tip: This function can be used to prepare strings for strings stored in the database as well as database query statements.
Note: By default, PHP automatically runs addslashes() on all GET, POST and COOKIE data. So you should not use addslashes() on already escaped strings, as this will result in double escaping. When encountering this situation, you can use the function get_magic_quotes_gpc() to detect it.
Recommended: "PHP Video Tutorial"
Grammar
addslashes(string)
Parameters
string required. Specifies the string to be escaped.
Add a backslash before each double quote ("):
<?php $str = addslashes('Shanghai is the "biggest" city in China.'); echo($str); ?>
Output:
Shanghai is the \"biggest\" city in China.
The above is the detailed content of How to escape double quotes in php. For more information, please follow other related articles on the PHP Chinese website!