PHP Magic Quotes ____php

Source: Internet
Author: User
One, what is magic quotes

Reminder: This feature has been discarded from PHP 5.3.0 and will be removed from PHP 5.4.0.
So after version 5.4 the PHP profile is not found with the configuration information of the magic quotes

When opened, all ' (single quotes), "(double quotes), \ (backslash), and NULL characters are automatically escaped with a backslash. This is exactly the same as the addslashes () function.

A total of three magic quote instructions:

1. MAGIC_QUOTES_GPC affects HTTP request data (Get,post and cookies). Cannot be changed at run time. In PHP, the default value is on. See GET_MAGIC_QUOTES_GPC ().

2, Magic_quotes_runtime if opened, most of the data obtained from external sources and returned functions, including from the database and text files, the returned data will be escaped by backslash. This option can be changed at run time, and the default value in PHP is off. See Set_magic_quotes_runtime () and Get_magic_quotes_runtime ().

3, Magic_quotes_sybase if open, will use single quotes to escape rather than backslash. This option will completely overwrite MAGIC_QUOTES_GPC. If you open two options at the same time, the single quote will be escaped. Double quotes, backslashes, and NULL characters are not escaped. How to get its value see Ini_get (). Ii. Description

Because the Magic Quote feature has been discarded from PHP 5.3.0 and will be removed from PHP 5.4.0, so we basically do not use this feature, just need to know about it.

There are four main functions for handling magic Quotes

function Description
Addcslashes () Returns a string that adds a backslash before the specified character.
Addslashes () Returns a string that adds a backslash before a predefined character.
Stripcslashes () Deletes the backslash that was added by the addcslashes () function.
Stripslashes () Deletes the backslash that was added by the addslashes () function.

Tip: A predefined character is a single quotation mark (') Double quotation mark (") backslash (\) NULL

Example

$var 1 = "abc ' 123";
$var 2 = ' abc ' 123 ';
$var 3 = ' abc\123 ';
$var 4 = "A001 A002 A003";

Addslashes () A string that adds a backslash before a predefined character

Var_dump (Addslashes ($var 1)); Echo ' <br> ';
Var_dump (Addslashes ($var 2)); Echo ' <br> ';
Var_dump (Addslashes ($var 3)); Echo ' <br> ';

Print

String (8) "Abc\ ' 123"
string (8) "Abc\ 123"

Stripslashes () Deletes the backslash that was added by the addslashes () function

Var_dump (Stripslashes (Addslashes ($var 1)); Echo ' <br> ';
Var_dump (Stripslashes (Addslashes ($var 2)); Echo ' <br> ';
Var_dump (Stripslashes (Addslashes ($var 3)); Echo ' <br> ';

Print

String (7) "ABC ' 123"
string (7) "ABC" 123 "

Addcslashes () A string that adds a backslash before the specified character

Var_dump (Addcslashes ($var 4, "A"));

Print

String (\a001 \a002 \a003)

Stripslashes () Deletes the backslash that was added by the addslashes () function.

Var_dump (Stripslashes (Addcslashes ($var 4, "A"));

Print

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.