How PHP quotes escape quickly _ PHP Tutorial

Source: Internet
Author: User
Quickly understand the principle of escaping PHP quotes. In PHP, we have three settings for automatic transfer of (single quotation marks), (double quotation marks), (backslash), and NULL characters. PHP calls it magic quotes. we are using these three settings.

PHP has three settings for automatic transfer of '(single quotation marks),' (double quotation marks), (backslash), and NULL characters.

PHP calls it magic quotes. these three settings are

Magic_quotes_gpc

Affects HTTP request data (GET, POST, and COOKIE ). It cannot be changed at runtime. In PHP, the default value is on.

Magic_quotes_runtime

If it is enabled, most of the functions that retrieve data from external sources and return data, including the database and text files, will be escaped by the backslash. This option can be changed at runtime. the default value in PHP is off.

Magic_quotes_sybase

If it is enabled, the single quotation marks are used to escape the single quotation marks in PHP, rather than the backslash. This option will completely overwrite magic_quotes_gpc. If two options are enabled at the same time, the single quotation marks will be converted ". Double quotation marks, backslash, and NULL characters are not escaped.

Although it is convenient to implement automatic PHP quotation mark escape for special characters, this will reduce the program efficiency and cause the program to be transplanted into trouble. If you do not know the settings of the server ini, you need to call get_magic_quotes_gpc (), get_magic_quotes_runtime () or ini_get () to check the status.

For example:

 
 
  1. if (!get_magic_quotes_gpc()) {
  2. $lastname = addslashes
    ($_POST['lastname']);
  3. } else {
  4. $lastname = $_POST['lastname'];
  5. }

Therefore, it is best to disable the magic quotation marks of php and manually use addslashes () and stripslashes () to escape and cancel the escape of PHP quotation marks. You can learn about discuz and add set_magic_quotes_runtime (0); to the configuration file to cancel escape.


PHP has three settings for automatic (single quotation marks), (double quotation marks), (backslash), and NULL character transfer. PHP calls it magic quotes. these three settings are respectively...

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.