PARSE_STR functions that can automatically split query characters in PHP use the example _php instance

Source: Internet
Author: User

Directly on the code:

Copy Code code as follows:

$str = "1&errid=1&fee=2&balance=2582&fails=&msgid=634541149212681528&msg= all sent successfully. ";
Parse_str ($str, $output);
echo $output [' MsgId ']; Output 634541149212681528

Definitions and usage

The Parse_str () function parses the query string into a variable.

Grammar

Parse_str (String,array)

Parameter description
String required. Specify the string to parse.
Array is optional. Specify the array name of the stored variable. This parameter indicates that the variable is stored in the array.

Tips and comments

Note: If the array parameter is not set, the variable set by the function overrides the variable with the same name.

Note: The MAGIC_QUOTES_GPC setting in php.ini affects the output of this function. If enabled, the variable is converted by addslashes () before Parse_str () is parsed.

Example

Example 1

Copy Code code as follows:

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

Output:
Copy Code code as follows:

23
John Adams

Example 2
Copy Code code as follows:

<?php
Parse_str ("Id=23&name=john%20adams", $myArray);
Print_r ($myArray);
?>

Output:
Copy Code code as follows:

Array
(
[ID] => 23
[Name] => John Adams
)

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.