Php addslashes function and SQL anti-injection, addslashessql_PHP tutorial

Source: Internet
Author: User
In php, the addslashes function and SQL anti-injection, addslashessql. In php, the addslashes function and the SQL anti-injection function are provided. This document describes the addslashes function and the SQL anti-injection function in php. Share it with you for your reference. The specific analysis is as follows: addslashes can be used for php addslashes functions and SQL anti-injection, addslashessql

This article describes the addslashes function and SQL anti-injection in php. Share it with you for your reference. The specific analysis is as follows:

Addslashes can automatically add "\" to single quotes and double quotation marks, so that we can securely store data into the database without being exploited by hackers. parameter 'a .. z' defines that all uppercase and lowercase letters are escaped. the code is as follows:

The code is as follows:

Echo addcslashes ('foo [] ', 'A. z'); // output: foo []
$ Str = "is your name o 'Reilly? "; // Define a string, including characters to be escaped
Echo addslashes ($ str); // output the escaped string


Definition and usage: the addslashes () function adds a backslash before a specified predefined character.

The predefined characters are: single quotation marks ('), double quotation marks ("), backslash (), and null.

Syntax: addslashes (string). of course, this function is safer. the instance code is as follows:

The code is as follows:

$ Str = "test"; // define a string containing special characters
$ New = htmlspecialchars ($ str, ent_quotes); // Convert
Echo $ new; // output the conversion result
// Used for output
$ Str = "jane & 'tarzance'"; // defines an html string.
Echo html_entity_decode ($ str); // output the converted content
Echo"
";
Echo html_entity_decode ($ str, ent_quotes); // optional parameter output

I hope this article will help you with PHP programming.

Examples in this article describes the addslashes function and SQL anti-injection in php. Share it with you for your reference. The specific analysis is as follows: addslashes can...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.