71 of 410 menu

The parse_str Function

The parse_str function parses a string with GET parameters into an array. This refers to a string of the following form:

'var1=value1&var2=value2'

The string to be parsed is passed as the first parameter, and the second parameter should be the name of the variable in which the result will be stored.

Syntax

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

Example

Let's parse a string into an array:

<?php $str = 'var1=value1&var2=value2'; parse_str($str, $arr); var_dump($arr); ?>

The code execution result:

['var1'=>'value1', 'var2'=>'value2']

See Also

  • the explode function,
    which splits a string into an array by a delimiter
  • the str_split function,
    which splits a string into an array by length
byenru