Phpaddslashes uses recursion to reference a string using a backslash _ PHP-php Tutorial

Source: Internet
Author: User
The following is a detailed analysis of using recursive implementation in php to reference strings using backslash. For more information, see Implementation code:
The code is as follows:
Function addslashes_deep ($ value)
{
// The most classic recursion in history, done in one row
Return is_array ($ value )? Array_map ('addslashes _ deep ', $ value): addslashes ($ value );
}

// Test data
$ _ POST ['str'] = "'hanglor 'is \ a boy> '";
$ _ GET ['str1'] = 'hanglor "is \ a boy> ';

Echo 'the current get_magic_quotes_gpc is '. get_magic_quotes_gpc ();
Echo"
";

// Determine whether get_magic_quotes_gpc is enabled.
If (! Get_magic_quotes_gpc ()){
$ _ POST = addslashes_deep ($ _ POST );
$ _ GET = addslashes_deep ($ _ GET );
$ _ COOKIE = addslashes_deep ($ _ COOKIE );
}

// Print the result
Var_dump ($ _ POST );
Echo"
";
Var_dump ($ _ GET );

?>

Print result:
The current get_magic_quotes_gpc value is 0.
Array (1) {["STR"] => string (30) "\ 'hanglor \ 'is \ a boy> \'"}
Array (1) {["STR1"] => string (26) "fanglor \" is \ a boy> "}

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.