parse_str() function in PHP


The parse_str() function is used to parse the string into variables. It returns nothing.

Syntax

parse_str(str, arr)

Parameters

  • str − The string to pass

  • arr − The name of an array to store the variables

Return

The parse_str() function returns nothing.

Example

The following is an example −

 Live Demo

<?php
   parse_str("studentname=Jack&marks=95",$arr);
   print_r($arr);
?>

Output

The following is the output −

Array
(
   [studentname] => Jack
   [marks] => 95
)

Example

Let us see another example −

 Live Demo

<?php
   parse_str("studentname=Tom&studentmarks=95&studentsubject=Maths", $arr);
   print_r($arr);
?>

Output

The following is the output −

Array
(
   [studentname] => Tom
   [studentmarks] => 95
   [studentsubject] => Maths
)

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 26-Dec-2019

27 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements