Overview

Url

A Uri models a URL, providing component access and modification through the PSR7 UriInterface.

<?php

use webignition\Uri\Uri;

$uri = new Uri('http://example.com/path?query#fragment');

$uri->getScheme();
// "http"

$uri->getQuery();
// "query"

$modifiedUri = $uri
    ->withScheme('https')
    ->withPath('/modified-path')
    ->withQuery('foo=bar')
    ->withFragment('');
(string) $modifiedUri;
// https://example.com/modified-path?foo=bar

Read the Uri usage guide for more detail.

Normalizer

The Normalizer can apply any combination of sixteen normalizations to any UriInterface implementation.

<?php

use webignition\Uri\Normalizer;

$uri = new Uri('http://example.com/path?c=cow&a=apple&b=bear#fragment');

$normalizedUri = Normalizer::normalize(
    $uri,
    Normalizer::SORT_QUERY_PARAMETERS | Normalizer::REMOVE_FRAGMENT
);

(string) $normalizedUri;
// "http://example.com/path?a=apple&b=bear&c=cow"

Flags:

Options:

Read the Normalizer usage guide for more detail.

Parser

The Parser transforms a URL string into an array of component parts. Useful for direct access to raw URL components.

The parser is used internally by Uri::create() and isn’t needed for normal URL usage.

<?php

use webignition\Uri\Parser;

$components = Parser::parse('https://example.com:8080/path?query#fragment');

$components[Parser::COMPONENT_SCHEME];
// "https"

$components[Parser::COMPONENT_HOST];
// "example.com"