wp_parse_str( string $input_string, array $result )

Parses a string into variables to be stored in an array.

Parameters

$input_stringstringrequired
The string to be parsed.
$resultarrayrequired
Variables will be stored in this array.

Source

function wp_parse_str( $input_string, &$result ) {
	parse_str( (string) $input_string, $result );

	/**
	 * Filters the array of variables derived from a parsed string.
	 *
	 * @since 2.2.1
	 *
	 * @param array $result The array populated with variables.
	 */
	$result = apply_filters( 'wp_parse_str', $result );
}

Hooks

apply_filters( ‘wp_parse_str’, array $result )

Filters the array of variables derived from a parsed string.

Changelog

VersionDescription
2.2.1Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Let’s say, you have an URL with query parameters. And you need query parameter values in an Array.

    $url = 'https://xyz.com/?a=10&b=20';
    $parse_url = wp_parse_url( $url );
    
    // 	Value of $parse_url
    //	Array
    //	(
    //	    [scheme] => https
    //	    [host] => xyz.com
    //	    [path] => /
    //	    [query] => a=10&b=20
    //	)
    
    $args = [];
    wp_parse_str( $parse_url[ 'query' ], $args );
    
    //	Value of $args
    //	Array
    //	(
    //	    [a] => 10
    //	    [b] => 20
    //	)

You must log in before being able to contribute a note or feedback.