Php parses the query string to a variable

Source: Internet
Author: User
Tags php tutorial

The parse_str () function parses the query string to a variable.

Syntax
Parse_str (string, array)
Note: If the array parameter is not set, the variables set by this function will overwrite the variables with the same name.


*/

Parse_str ("id = 23 & name = john % 20 adams ");
Echo $ id. "<br/> ";
Echo $ name;

// 23
// John

$ Str = "first = value & arr [] = foo + bar & arr [] = baz"; // define a string
Parse_str ($ str); // parses the string into a variable.
Echo $ first; // output the value of $ first
Echo "<br> ";
Echo $ arr [0]; // output the value of $ arr [0] foo bar
Echo "<br> ";
Echo $ arr [1]; // Output $ arr [1] value baz
Echo "<br> ";
Parse_str ($ str, $ output); // stores the variable parsed by the string in $ output.
Echo $ output ['first']; // output the value of $ first.
Echo "<br> ";
Echo $ output ['arr'] [0]; // output the value of $ arr [0] foo bar.
Echo "<br> ";
Echo $ output ['arr'] [1]; // outputs the value baz of $ arr [1].

/*

Note: The magic_quotes_gpc setting in php Tutorial. ini affects the output of this function. If enabled, the variable will be converted by addslashes () before parse_str () resolution.

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.