PHP parse_str() Function

Example

Parse the query string into variables:

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

Run Instances

Definition and Usage

The parse_str() function parses the query string into variables.

Note:If not set array If the parameter is not set, the variables set by the 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 will be converted by addslashes() before parse_str() parses them.

Syntax

parse_str(<
i>string,array)
Parameter Description
string Required. Specifies the string to be parsed.
array Optional. Specifies the name of the array in which the variable is to be stored. This parameter indicates that the variable will be stored in the array.

Technical Details

Return Value: No Return Value.
PHP Version: 4+
Update Log: Added in PHP 4.0.3: array Parameters.

More Examples

Example 1

Store Variables in an Array:

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

Run Instances