Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

PHP | parse_str() Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The parse_str() function is a built-in function in PHP which parses a query string into variables. The string passed to this function for parsing is in the format of a query string passed via a URL.

Syntax :

parse_str($string, $array)

Parameters: This function accepts two parameters as shown in the above syntax out of which the first parameter must be supplied and the second one is optional. All of these parameters are described below:

  • $string: It specifies the string to parse.
  • $array: This is an optional parameter which specifies the name of an array to store the variables. This parameter indicates that the variables will be stored in an array.


Input : "name=Richik&age=20"
Output :  $name = Richik
          $age = 20

Input : "roll_no=2&year=2nd&gpa=8.3"
Output : $roll_no = 2
         $year = 2nd
         $gpa = 8.3

Below programs illustrate the parse_str() function in PHP:

Program 1 :

    echo $name."\n".$age;



Program 2:In this program we will store the variables in an array and then display the array using print_r() function.

    parse_str("roll_no=2&year=2nd&gpa=8.3", $array);


    [roll_no] => 2
    [year] => 2nd
    [gpa] => 8.3


My Personal Notes arrow_drop_up
Last Updated : 27 Mar, 2018
Like Article
Save Article
Similar Reads
Related Tutorials