The League of Extraordinary Packages

Our Packages:

Presented by The League of Extraordinary Packages


Modern API to process URI in PHP.

$ composer require league/uri


Current Stable


  • Requires: PHP >= 7.0.0
  • Latest: 5.3.0 - 2018-03-14
  • Supported Until: TBD

Full Documentation



  • Requires: PHP >= 5.5.9
  • Latest: 4.2.3 - 2017-10-17
  • Supported Until: 2017-08-06

Full Documentation

Once a new major version is released, the previous stable release remains supported for six more months through patches and security fixes.


The library provides simple and intuitive classes to parse, validate, format and manipulate URIs and their components. It is built to enable working with any kind of RFC3986 compliant URI through extensions and middlewares.

  1. Simple and extensible API

  2. RFC3986 compliant

  3. Implements PSR-7 UriInterface interface

  4. Framework-agnostic


Parsing URI

The League URI Parser parses any given URI according to RFC3986 rules


use League\Uri;

//returns the following array
//  'scheme' => 'http',
//  'user' => null,
//  'pass' => null,
//  'host' => '',
//  'port' => null,
//  'path' => '',
//  'query' => '',
//  'fragment' => null,

Normalizing URI

League URI objects normalize the URI string according to RFC3986/RFC3987 non destructive rules.


use League\Uri;

$uri = Uri\create("hTTp:// ld?who=f 3#title");
echo $uri; //displays

$uri = Uri\Http::createFromComponent(parse_url("hTTp://www.bébé.be?#"));
echo $uri; //displays

URI Middlewares

A collection of URI middlewares to enable reliable URI modifications with any given League URI object or PSR-7 UriInterface compatible implementation.


use League\Uri;
use Zend\Diactoros\Uri as DiactorosUri;

$uri = new DiactorosUri("");
$new_uri = Uri\merge_query($uri, 'fo.o=bar&taz=');
echo $new_uri;
// display
// $new_uri is a Zend\Diactoros\Uri instance

URI components

Improve URI components manipulations through dedicated objects.


use League\Uri\Components\Host;

$host = new Host('');
echo $host->getPublicSuffix();        //display ''
echo $host->getRegisterableDomain();  //display ''
echo $host->getSubdomain();           //display 'www'
$host->isPublicSuffixValid();         //return a boolean 'true' in this example


URI was created by Ignace Nyamagana Butera. Find him on Twitter at @nyamsprod.