PHP parse_str() Function - Tutorial Republic

Topic: PHP String ReferencePrev|Next

Description

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

The following table summarizes the technical details of this function.

Return Value: No value is returned.
Changelog: Since PHP 7.2.0, the array parameter is required.
Version: PHP 4+

Syntax

The basic syntax of the parse_str() function is given with:

parse_str(string, result);

The following example shows the parse_str() function in action.

<?php
// Sample String
$str = "name=Harry&age=18";

// Parsing query string
parse_str($str, $result);
echo $result["name"]; // Outputs: Harry
echo $result["age"];  // Outputs: 18 
?>

Parameters

The parse_str() function accepts the following parameters.

Parameter Description
string Required. Specifies the string to parse.
result Required. Specifies that the variables are stored in this variable as array elements.