W3Schools.com

PHP parse_str() Function


PHP String Reference Complete PHP String Reference

Definition and Usage

The parse_str() function parses a query string into variables.

Syntax

parse_str(string,array)

Parameter Description
string Required. Specifies the string to parse
array Optional. Specifies the name of an array to store the variables. This parameter indicates that the variables will be stored in an array.

Note: This parameter was added in PHP 4.0.3



Tips and Notes

Note: If the array parameter is not set, variables set by this function will overwrite existing variables of the same name.

Note: The magic_quotes_gpc setting in the php.ini file affects the output of this function. If enabled, the variables are converted by addslashes() before parsed by parse_str().


Example 1

<?php
parse_str("id=23&name=Kai%20Jim");
echo $id."<br />";
echo $name;
?>

The output of the code above will be:

23
Kai Jim


Example 2

<?php
parse_str("id=23&name=Kai%20Jim",$myArray);
print_r($myArray);
?>

The output of the code above will be:

Array
(
[id] => 23
[name] => Kai Jim
)


PHP String Reference Complete PHP String Reference
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE