_get_component_from_parsed_url_array

Retrieve a specific component from a parsed URL array.

Description

_get_component_from_parsed_url_array( (array|false) $url_parts, (int) $component = -1 ); 

Parameters (2)

0. $url_parts (array|false)
The parsed URL. Can be false if the URL failed to parse.
1. $component — Optional. (int) => -1
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). @see http://php.net/manual/en/function.parse-url.php

Usage

  1. if ( !function_exists( '_get_component_from_parsed_url_array' ) ) { 
  2. require_once ABSPATH . WPINC . '/http.php'; 
  3.  
  4. // The parsed URL. Can be false if the URL failed to parse. 
  5. $url_parts = null; 
  6. $component = -1; 
  7.  
  8. // NOTICE! Understand what this does before running. 
  9. $result = _get_component_from_parsed_url_array($url_parts, $component); 
  10.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/http.php  
  1. function _get_component_from_parsed_url_array( $url_parts, $component = -1 ) { 
  2. if ( -1 === $component ) { 
  3. return $url_parts; 
  4.  
  5. $key = _wp_translate_php_url_constant_to_key( $component ); 
  6. if ( false !== $key && is_array( $url_parts ) && isset( $url_parts[ $key ] ) ) { 
  7. return $url_parts[ $key ]; 
  8. } else { 
  9. return null;