Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Uri.php

function Uri::parse

UTF-8 aware \parse_url() replacement.

The internal function produces broken output for non ASCII domain names (IDN) when used with locales other than "C".

On the other hand, cURL understands IDN correctly only when UTF-8 locale is configured ("C.UTF-8", "en_US.UTF-8", etc.).

Return value

array|false

See also

https://bugs.php.net/bug.php?id=52923

https://www.php.net/manual/en/function.parse-url.php#114817

https://curl.haxx.se/libcurl/c/CURLOPT_URL.html#ENCODING

1 call to Uri::parse()
Uri::__construct in vendor/guzzlehttp/psr7/src/Uri.php

File

vendor/guzzlehttp/psr7/src/Uri.php, line 106

Class

Uri
PSR-7 URI implementation.

Namespace

GuzzleHttp\Psr7

Code

private static function parse(string $url) {
    // If IPv6
    $prefix = '';
    if (preg_match('%^(.*://\\[[0-9:a-f]+\\])(.*?)$%', $url, $matches)) {
        
        /** @var array{0:string, 1:string, 2:string} $matches */
        $prefix = $matches[1];
        $url = $matches[2];
    }
    
    /** @var string */
    $encodedUrl = preg_replace_callback('%[^:/@?&=#]+%usD', static function ($matches) {
        return urlencode($matches[0]);
    }, $url);
    $result = parse_url($prefix . $encodedUrl);
    if ($result === false) {
        return false;
    }
    return array_map('urldecode', $result);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal