Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

parse_str

Parses a query string into an array.

Syntax

parse_str(string $string, array &$result): void

Parameters

ParameterTypeDescription
$stringstringA string like `a=1&b=2`.
$resultarrayReceives the result.

Return value

voidThe function returns nothing.

Examples

Parameters from an address:

<?php
 
parse_str(parse_url('https://example.com/search?q=php+book&tags[]=new&tags[]=sale', PHP_URL_QUERY), $params);
 
echo json_encode($params);

Output:

{"q":"php book","tags":["new","sale"]}

Notes

Values are decoded automatically, and square brackets in names turn into arrays.

See also

Related recipes

In the tutorial

  • HTTP requests and responses — How PHP receives a request and builds a response — the request method and address, headers, status codes, redirects and JSON responses.

Thanks for reading!

Donate to the site — we work hard for you.