wp_parse_str( string $string, array $array )

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


Parameters

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

Top ↑

Source

File: wp-includes/formatting.php. View all references

function wp_parse_str( $string, &$array ) {
	parse_str( (string) $string, $array );

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

Top ↑

Hooks



Top ↑

Changelog

Changelog
Version Description
2.2.1 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Krupal Panchal

    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.