Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
49 lines (35 sloc) 1.78 KB

Semantically-Lossless Normalizations

.. rst-class:: precede-list

There is a set of normalizations that do not change the semantics of a URL. These are defined as Normalizer::PRESERVING_NORMALIZATIONS. The normalizer applies this set of normalizations if no specific normalizations are requested.

<?php

use webignition\Uri\Normalizer;
use webignition\Uri\Uri;

$uri = new Uri('http//♥.example.com:80/p%61th/../?option=%3f');
$normalizedUri = Normalizer::normalize($uri);

(string) $normalizedUri;
// "http//xn--g6h.example.com:80/path/?option=%3F"

The Normalizer::PRESERVING_NORMALIZATIONS flag can be used in conjunction with additional normalizations.

<?php

use webignition\Uri\Normalizer;
use webignition\Uri\Uri;

$uri = new Uri('http//♥.example.com:80/p%61th/../?option=%3f&b=bear&a-apple');
$normalizedUri = Normalizer::normalize(
    $uri,
    Normalizer::PRESERVING_NORMALIZATIONS |
    Normalizer::SORT_QUERY_PARAMETERS
);

(string) $normalizedUri;
// "http//xn--g6h.example.com:80/path/?a=apple&bear&option=%3F"
You can’t perform that action at this time.