php

Query String


 

The parse_str() function in PHP parses a query string and translates it into variables. It takes a string containing variable assignments in the form of name=value pairs separated by ampersands (&). These pairs are then converted into variables in the current symbol table of the script.

 

Here's the basic syntax:

<?php
		parse_str(string, array);
	?>

 

Example:

<?php
    	parse_str("name=Rahul&skill=php");
    	echo $name."<br>";
    	echo $skill;
	?>

 

Note: If the array parameter is not set in the parse_str() function, the variables will be introduced directly into the current symbol table. If a variable with the same name already exists, it will be overwritten by the newly parsed value from the query string.


The query string is a way to include data in the URL, often used for parameters that influence the content or behaviour of the requested resource on the web server.
 

Example:

https://www.learnCodingOfficial.com/worker?name=Raj&dept=it&role=phpdeveloper

 

In the above url, 'name=Raj&dept=it&role=phpdeveloper' is the query string, having multiple parameters. The parameters are separated by '&' and within each pair, the field name and value are separated by an equal sign(=).