Title: _get_component_from_parsed_url_array
Published: December 7, 2016
Last modified: May 20, 2026

---

# _get_component_from_parsed_url_array( array|false $url_parts, int $component = -1 ): mixed

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/_get_component_from_parsed_url_array/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/_get_component_from_parsed_url_array/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/_get_component_from_parsed_url_array/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/_get_component_from_parsed_url_array/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_get_component_from_parsed_url_array/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/_get_component_from_parsed_url_array/?output_format=md#wp--skip-link--target)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Retrieves a specific component from a parsed URL array.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/_get_component_from_parsed_url_array/?output_format=md#parameters)󠁿

 `$url_parts`array|falserequired

The parsed URL. Can be false if the URL failed to parse.

`$component`intoptional

The specific component to retrieve. Use one of the PHP predefined constants to specify
which one.
 Defaults to -1 (= return all parts as an array).

Default:`-1`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/_get_component_from_parsed_url_array/?output_format=md#return)󠁿

 mixed False on parse failure; Array of URL components on success; When a specific
component has been requested: null if the component doesn’t exist in the given URL;
a string or – in the case of PHP_URL_PORT – integer when it does. See parse_url()’
s return values.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/_get_component_from_parsed_url_array/?output_format=md#source)󠁿

    ```php
    function _get_component_from_parsed_url_array( $url_parts, $component = -1 ) {
    	if ( -1 === $component ) {
    		return $url_parts;
    	}

    	$key = _wp_translate_php_url_constant_to_key( $component );
    	if ( false !== $key && is_array( $url_parts ) && isset( $url_parts[ $key ] ) ) {
    		return $url_parts[ $key ];
    	} else {
    		return null;
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/http.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/http.php#L817)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/http.php#L817-L828)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/_get_component_from_parsed_url_array/?output_format=md#related)󠁿

| Uses | Description | 
| [_wp_translate_php_url_constant_to_key()](https://developer.wordpress.org/reference/functions/_wp_translate_php_url_constant_to_key/)`wp-includes/http.php` |

Translates a PHP_URL_* constant to the named array keys PHP uses.

  |

| Used by | Description | 
| [wp_parse_url()](https://developer.wordpress.org/reference/functions/wp_parse_url/)`wp-includes/http.php` |

A wrapper for PHP’s parse_url() function that handles consistency in the return values across PHP versions.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/_get_component_from_parsed_url_array/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2F_get_component_from_parsed_url_array%2F)
before being able to contribute a note or feedback.