Skip to content
Parse, build and manipulate URL's
PHP
Branch: master
Clone or download
Latest commit fe89b6c Nov 13, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Apply fixes from StyleCI Nov 13, 2019
tests Apply fixes from StyleCI Nov 13, 2019
.editorconfig First commit Sep 12, 2016
.gitattributes First commit Sep 12, 2016
.gitignore First commit Sep 12, 2016
.scrutinizer.yml First commit Sep 12, 2016
.styleci.yml Test enhancement May 3, 2018
.travis.yml Update .travis.yml Nov 13, 2019
CHANGELOG.md Update CHANGELOG.md Jan 2, 2018
CONTRIBUTING.md Refactoring & adding PHP 7.2 support Sep 18, 2017
LICENSE.md Remove year number in the license Jan 2, 2018
README.md Update README.md Dec 29, 2018
composer.json Update composer.json Nov 13, 2019
phpunit.xml.dist First commit Sep 12, 2016

README.md

Parse, build and manipulate URL's

Latest Version on Packagist Software License Build Status StyleCI Total Downloads

A simple package to deal with URL's in your applications.

Retrieve parts of the URL:

use Spatie\Url\Url;

$url = Url::fromString('https://spatie.be/opensource');

echo $url->getScheme(); // 'https'
echo $url->getHost(); // 'spatie.be'
echo $url->getPath(); // '/opensource'

Transform any part of the URL (the Url class is immutable):

$url = Url::fromString('https://spatie.be/opensource');

echo $url->withHost('github.com')->withPath('spatie');
// 'https://github.com/spatie'

Retrieve and transform query parameters:

$url = Url::fromString('https://spatie.be/opensource?utm_source=github&utm_campaign=packages');

echo $url->getQuery(); // 'utm_source=github&utm_campaign=packages'
echo $url->getQueryParameter('utm_source'); // 'github'
echo $url->withoutQueryParameter('utm_campaign'); // 'https://spatie.be/opensource?utm_source=github'

Retrieve path segments:

$url = Url::fromString('https://spatie.be/opensource/laravel');

echo $url->getSegment(1); // 'opensource'
echo $url->getSegment(2); // 'laravel'

Implements PSR-7's UriInterface interface:

class Url implements UriInterface { /* ... */ }

The league/uri is a more powerful package than this one. The main reason this package exists, is because the alternatives requires non-standard php extensions. If you're dealing with special character encodings or need bulletproof validation, you're definitely better off using league/uri.

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

Installation

You can install the package via composer:

composer require spatie/url

Usage

Usage is pretty straightforward. Check out the code examples at the top of this readme.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email freek@spatie.be instead of using the issue tracker.

Postcardware

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

Support us

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.

License

The MIT License (MIT). Please see License File for more information.

You can’t perform that action at this time.