A simple package to deal with URL's in your applications.
Retrieve parts of the 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=pacakges');
echo $url->getQuery(); // 'utm_source=github&utm_campaign=pacakges'
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 the alternative 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.
You're free to use this package (it's MIT-licensed), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using.
Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.
The best postcards will get published on the open source page on our website.
You can install the package via composer:
composer require spatie/url
There are some code examples at the top of this readme.
Please see CHANGELOG for more information what has changed recently.
$ composer test
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
The MIT License (MIT). Please see License File for more information.