What is the purpose of the php parse_str function?

The parse_str function is a built-in function in PHP that is used to parse a query string into variables. In other words, it takes a URL query string (e.g. key1=value1&key2=value2) and converts it into one or more variables, assigning these variables to the corresponding key names in the current symbol table (usually an array).

The syntax of this function is:

void parse_str(string $str, array &$result)

$str is the query string to be parsed and $result is the array used to store the parsing results.

For example:

$queryString = "name=John&age=30";
parse_str($queryString, $parsedData);
print_r($parsedData);

The output result is:

Array
(
    [name] => John
    [age] => 30
)

This will allow for easily converting URL query strings into variables in PHP, making them easier to handle and use later on.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds