Home >Backend Development >PHP Tutorial >PHP parses the query string into a variable using the function parse_str()

PHP parses the query string into a variable using the function parse_str()

黄舟
黄舟Original
2017-11-02 13:54:111813browse

Example

Parse the query string into a variable:

<?php
parse_str("name=Peter&age=43");
echo $name."<br>";
echo $age;
?>

Definition and usage

parse_str() function parses the query string into a variable.

Note: If the array parameter is not set, the variables set by this function will overwrite the existing variables with the same name.

Note: The magic_quotes_gpc setting in the php.ini file affects the output of this function. If enabled, variables are converted by addslashes() before being parsed by parse_str() .

Syntax

parse_str(string,array)

Parameter Description

string Required. Specifies the string to parse.

array Optional. Specifies the name of the array to store the variable. This parameter instructs the variable to be stored in an array.

Technical details

Return value: No return value.

PHP Version: 4+

##Change Log: In PHP 4.0.3 , added array parameter.

More examples

Example 1

Storage variables into an array:

<?php
parse_str("name=Peter&age=43",$myArray);
print_r($myArray);
?>

Convert the url parameter string into Array

$str = ‘a=1&b=2&c=3’;
parse_str($str, $arr);
var_dump($arr);
//输出
rrree

The above is the detailed content of PHP parses the query string into a variable using the function parse_str(). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn