PHP parse_str Function: Usage, Parameters, and Examples
This article explains PHP's parse_str() function, detailing its purpose of converting query strings into variables, describing its parameters and void return, and providing clear code examples demonstrating both basic usage and usage with an output array.
parse_str() parses a query string into variables.
If the input string is a URL query string, it creates variables in the current scope or stores them in an array when a second argument is provided.
Parameters
str : the input string.
arr (optional): an array that will receive the variables as elements.
Return value
None (void).
Example
<?php
$str = "first=value&arr[]=foo+bar&arr[]=baz";
parse_str($str);
echo $first; // value
echo $arr[0]; // foo bar
echo $arr[1]; // baz
// Using second argument
parse_str($str, $output);
echo $output['first']; // value
echo $output['arr'][0]; // foo bar
echo $output['arr'][1]; // baz
?>Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
