Normalize URL’s with PHP

I’ve posted to GitHub a PHP class that I’ve written which can handle URL normalization, as specified by RFC 3986.

https://github.com/glenscott/url-normalizer

Specifically, the following normalization steps are performed:

  1. Normalize case
  2. Decode unreserved characters
  3. Remove dot segments

An example of use:

require_once 'URLNormalizer.php';
 
$url = 'eXAMPLE://a/./b/../b/%63/%7bfoo%7d';
$un = new URLNormalizer();
$un->setUrl( $url );
echo $un->normalize();

// result: "example://a/b/c/%7Bfoo%7D"

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

4 thoughts on “Normalize URL’s with PHP

  1. Xiphe

    Hey, your github repro does not provide informations about licensing.
    I would like to add your URLNormalizer class to a wordpress plugin/framework i’m developing witch is available under the GNUv2 License.

    Would that be okay for you?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.