Monday, 29 September 2014

parse_str in PHP

PHP  parse_str() function is utilized a query string is parsed into variables via URL and returned.

Syntax:

parse_str(string,array)
string : Required. Defines the input string.

array : Optional. If present, it stores variables as array elements.

Note : Provided that the array parameter is not situated, variables set by PHP parse_str()function will overwrite existing variables of the same name.

The magic_qoutes_gpc setting in the php.ini file influences the output of this PHP parse_str() function.

Example:

<?php
parse_str( 'id=101&name=Jim%20Thomas' );
echo $id."<br />";
echo $name."<br />";
parse_str( 'id=101&name=Jim%20Thomas',$array_name );
print_r($array_name);
?>
Output will be:
101 
Jim Thomas 
Array ( [id] => 101 [name] => Jim Thomas )

0 comments:

Post a Comment