Phpaddslashes uses recursive implementations to reference strings using backslash _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Phpaddslashes uses recursion to reference strings using backslash. Implementation Code: Copy the code as follows :? Phpfunctionaddslashes_deep ($ value) {the most classic recursion in history. how does one row get returnis_array ($ value )? Array_map (addslashes_deep, 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> "}

The pipeline code is as follows :? Php function addslashes_deep ($ value) {// The most classic recursion in history. can return is_array ($ value) be implemented in one row )? Array_map ('addslashes _ deep ',...

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.