The addslashes function in php and sql anti-injection, addslashessql
The example in this article describes the addslashes function and SQL injection prevention in php. Share it with everyone for your reference. The specific analysis is as follows:
addslashes can automatically add \\\ to single quotes and double quotes, so that we can safely store data in the database without being exploited by hackers. The parameter 'a..z' defines that all uppercase and lowercase letters will be converted Meaning, the code is as follows:
Copy code The code is as follows:
echo addcslashes('foo[ ]','a..z'); //Output: foo[ ]
$str="is your name o'reilly?"; //Define a string, including characters that need to be escaped
echo addslashes($str); //Output the escaped string
Definition and usage: The addslashes() function adds a backslash before the specified predefined characters.
These predefined characters are: single quote ('), double quote ("), backslash (), null
Syntax: addslashes(string), of course this function is safer, the example code is as follows:
Copy code The code is as follows:
$str="
test"; //Definition String containing special characters
$new=htmlspecialchars($str,ent_quotes); //Perform conversion operation
echo $new; //Output the conversion result
//But you need to use
when outputting
$str="jane & 'tarzan'"; //Define html string
echo html_entity_decode($str); //Output the converted content
echo "
";
echo html_entity_decode($str,ent_quotes); //Content output with optional parameters
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/912673.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/912673.htmlTechArticleaddslashes function and sql anti-injection in php, addslashessql This article describes the addslashes function and sql anti-injection in php. Share it with everyone for your reference. The specific analysis is as follows: addslashes can...