Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
URI constructor.
PHP
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
tests Renamned deluded option key.
README.md Renamned deluded option key.
Uri.php Strict pear coding standard applied.

README.md

Introduction

One URI constructor to rule them all. A simple class that makes URI constructing a real pleasure. The class make use of the magic method called __toString in PHP.

The code is straightforward, well documentated and tested.

Examples

See examples below. Also make sure to check out the test suite which (hopefully) covers all use cases.

Construct URI

<?php
$uri = new Uri('example.com');

echo $uri;
// => http://example.com/

Construct URI with path

<?php
$uri = new Uri('example.com', 'blog');

echo $uri;
// => http://example.com/blog

Construct URI with multiple paths

<?php
$uri = new Uri('example.com', array('blog', 'foobar'));

echo $uri;
// => http://example.com/blog/foobar

Construct URI with custom options

<?php
$uri = new Uri(
    'example.com',
    array('blog', 'foobar'),
    array('ssl' => true, 'parameters' => array('foo' => 'bar'))
);

echo $uri;
// => https://example.com/blog/foobar?foo=bar

Construct URI and pass as a string

<?php
$uri = new Uri('example.com');

Foo::bar((string)$uri);

Options

Key Type Default Description
encode boolean false Encode the URI.
hash array null Hash parameters.
parameters array null Query string parameters.
password string null Password. Must be accompanied with a username.
port integer 80 Port number. Will be included in the URI if other than 80 or 443.
protocol string http Protocol.
separator string & Query string and hash parameters separator.
ssl boolean false SSL. If true an s will be appended to the given protocol.
username string null Username.

License

Copyright (c) 2011 Anton Lindqvist

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.