Home » PHP1 July 2010

PHP: Parse Unparse String Array

Here is a quick tip on parsing and unparsing string and array in PHP.

You can parses the string into variables by using the parse_str PHP function.

Using parse_str function

void parse_str ( string $str [, array &$arr ] )

$str = The input string.
$arr = If the second parameter arr is present, variables are stored in this variable as array elements instead.

Using single parameter

Using the second parameter

The output will be:-

You can unparse any array into string using the http_build_query function. This generates a URL-encoded query string from the associative (or indexed) array provided.

Hope this helps. Thanks.


Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed