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()

黄舟
Release: 2023-03-16 22:36:02
Original
1806 people have browsed it

Example

Parse the query string into a variable:

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

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)
Copy after login

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);
?>
Copy after login

Convert the url parameter string into Array

$str = ‘a=1&b=2&c=3’;
parse_str($str, $arr);
var_dump($arr);
//输出
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template