PHP parse_str() Function Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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. Examples: 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 : php <?php parse_str("name=Richik&age=20"); echo $name."\n".$age; ?> Output: Richik 20 Program 2:In this program we will store the variables in an array and then display the array using print_r() function. php <?php parse_str("roll_no=2&year=2nd&gpa=8.3", $array); print_r($array); ?> Output: Array ( [roll_no] => 2 [year] => 2nd [gpa] => 8.3 ) Reference: https://www.php.net/manual/en/function.parse-str.php Comment More info R RICHIK BHATTACHARJEE Follow Improve Article Tags : Misc Web Technologies PHP PHP-string Explore PHP Tutorial 8 min read BasicsPHP Syntax 4 min read PHP Variables 5 min read PHP | Functions 8 min read PHP Loops 4 min read ArrayPHP Arrays 5 min read PHP Associative Arrays 4 min read Multidimensional arrays in PHP 5 min read Sorting Arrays in PHP 4 min read OOPs & InterfacesPHP Classes 2 min read PHP | Constructors and Destructors 5 min read PHP Access Modifiers 4 min read Multiple Inheritance in PHP 4 min read MySQL DatabasePHP | MySQL Database Introduction 4 min read PHP Database connection 2 min read PHP | MySQL ( Creating Database ) 3 min read PHP | MySQL ( Creating Table ) 3 min read PHP AdvancePHP Superglobals 6 min read PHP | Regular Expressions 12 min read PHP Form Handling 4 min read PHP File Handling 4 min read PHP | Uploading File 3 min read PHP Cookies 9 min read PHP | Sessions 7 min read Like