PHP Parse URL Querystring Into Array

PHP Parse URL Querystring Into Array

Today, We want to share with you PHP Parse URL Querystring Into Array.
In this post we will show you Parse URL Querystring Into Array In PHP, hear for php – Parse query string into an array we will give you demo and example for implement.
In this post, we will learn about parse_str to Get Query String from URL in PHP with an example.

parse_str() to Get Query String from URL in PHP

PHP QUERY STRING

The parse_str() function parses a data query string into convert variables.Simple defination is parse_str(functions) — The Parses the string into convert variables

Read Also:  PHP MySQL Dynamic SQL Insert Query

The URL can pass along with parameters in the form submit of query string. and get PHP can retrieve all varibles and get the query string for manipulation data and handling in some functions and execute processes.

Syntax of parse_str() Function

 parse_str(string,array_name);

what is query string in php?

Your URL : http://www.examplesite.com/login.php?id=5&name=add_record
The query string is:?id=5&name=add_record
Access the value of the your query string : echo $id = $_GET['id'];

Get URL query string

parse_str($_SERVER['QUERY_STRING']);
$_SERVER["QUERY_STRING"]

Development

get parameters from a URL string?

$project = parse_url($url);
parse_str($project['query'], $querydata);
echo $querydata['email'];
or
echo $_GET['email'];

PHP Querystring Functions

$url_string = "https://example.com/soft/[email protected]&pass=9898";
$query_string = parse_url($url_string, PHP_URL_QUERY);
parse_str($query_string, $query_res);
print_r($query_res);

Output

 Array ( [email] => [email protected] [pass] => 9898 ) 

Parse URL Querystring Into Array In PHP

$str = "name=segement&arrval[]=kpi+segment&arrval[]=project";
parse_str($str, $data_val);
echo $data_val['name'];  // segement
echo $data_val['arrval'][0]; // kpi segment
echo $data_val['arrval'][1]; // project

php query string example

<!DOCTYPE html>
<html>
<body>

<?php
parse_str("name=kpi&age=28");
echo $name."<hr>";
echo $age;
echo "<br/>**********";
?>
 
</body>
</html>
[php]

<h3>Output</h3>
[php]
kpi
-------
28
********

Parse query string into an array

$get_data = "segement=A&kpi=2&project&data";
parse_str($get_data, $get_val);
print_r($get_val);

Retrieve & Get Query String from URL in PHP

way 1:
------
$_GET["uservalidname"];
$_POST["uservalidname"];
$_REQUEST["uservalidname"];

way 2:
------
<?php
   echo htmlspecialchars($_GET["uservalidname"]);
?>

way 3:
------
<?php
   echo $_SERVER["QUERY_STRING"];
?>

way 4:
------
parse_str($_SERVER["QUERY_STRING"]);

way 5:
------
parse_str($_SERVER["QUERY_STRING"], $query_array_datavalue);
print_r($query_array_datavalue);

We hope you get an idea about PHP Parse URL Querystring Into Array
We would like to have feedback on my Information blog .
Your valuable any feedback, Good question, Inspirational Quotes, or Motivational comments about this article are always welcome.
If you liked this post, Please don’t forget to share this as Well as Like FaceBook Page.

We hope This Post can help you…….Good Luck!.