Php parses the query string to a variable

Source: Internet
Author: User
The parse_str () function parses the query string to the variable. syntax: parse_str (string, array) Note: If the array parameter is not set, the variable set by this function overwrites the variable with the same name. The instance code is as follows :... the parse_str () function parses the query string to the variable.

Syntax:Parse_str (string, array)

Note:If the array parameter is not set, the variable set by this function overwrites the variable with the same name. The instance code is as follows:

*/

Parse_str ("id = 23 & name = john % 20 adams"); echo $ id ."
"; Echo $ name; // 23 // john $ str =" first = value & arr [] = foo + bar & arr [] = baz "; // define the string parse_str ($ str); // Parse the string into the variable echo $ first; // output the value of $ first echo"
"; Echo $ arr [0]; // output the value of $ arr [0] foo bar echo"
"; Echo $ arr [1]; // outputs the value of $ arr [1] baz echo"
"; Parse_str ($ str, $ output); // store string-parsed variables in $ output echo $ output ['first']; // Output $ first value echo"
"; Echo $ output ['arr'] [0]; // output the value of $ arr [0] foo bar echo"
"; Echo $ output ['arr'] [1]; // outputs the value baz of $ arr [1 ].

/*

Note:The magic_quotes_gpc setting in php. ini affects the output of this function. if it is enabled, the variable will be converted by addslashes () before parse_str () is parsed.


Tutorial link:

Reprint at will ~ However, please keep the tutorial address★

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.