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 more than 10 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 and the founder of FreelanceDevLeads, a service that sources quality freelance leads for developers.

More Posts

Follow Me:
TwitterFacebookLinkedIn

4 thoughts on “Normalize URL's with PHP

  1. Anthony Gill

    Nice work! I was just about to write something like this to clean up user-provided URLs. :) You rock.

  2. 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?

  3. Glen Scott Post author

    I've been meaning to add a BSD licence for some time. Feel free to use it in your GPL project.

Leave a Reply