2017 © Pedro Peláez
 

library url

Parse, build and manipulate URL's

image

spatie/url

Parse, build and manipulate URL's

  • Friday, May 4, 2018
  • by Spatie
  • Repository
  • 8 Watchers
  • 182 Stars
  • 132,115 Installations
  • PHP
  • 11 Dependents
  • 0 Suggesters
  • 21 Forks
  • 1 Open issues
  • 13 Versions
  • 21 % Grown

The README.md

Parse, build and manipulate URLs

Latest Version on Packagist Tests Total Downloads, (*1)

A simple package to deal with URLs in your applications., (*2)

Installation

You can install the package via composer:, (*3)

composer require spatie/url

Usage

Parse and transform a URL

Retrieve any part of the URL:, (*4)

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:, (*5)

Note the Url class is immutable., (*6)

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

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

Scheme

Transform the URL scheme., (*7)

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

echo $url->withScheme('https'); // 'https://spatie.be/opensource'

Use a list of allowed schemes., (*8)

Note each scheme in the list will be sanitized, (*9)

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

echo $url->withAllowedSchemes(['wss'])->withScheme('wss'); // 'wss://spatie.be/opensource'

or pass the list directly to fromString as the URL's scheme will be sanitized and validated immediately:, (*10)

$url = Url::fromString('https://spatie.be/opensource', [...SchemeValidator::VALID_SCHEMES, 'wss']);

echo $url->withScheme('wss'); // 'wss://spatie.be/opensource'

Query parameters

Retrieve and transform query parameters:, (*11)

$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->getQueryParameter('utm_medium'); // null
echo $url->getQueryParameter('utm_medium', 'social'); // 'social'
echo $url->getQueryParameter('utm_medium', function() {
    //some logic
    return 'email';
}); // 'email'

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

Path segments

Retrieve path segments:, (*12)

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

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

PSR-7 UriInterface

Implements PSR-7's UriInterface interface:, (*13)

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., (*14)

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

Testing

composer test

Support us

, (*16)

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products., (*17)

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall., (*18)

Changelog

Please see CHANGELOG for more information on what has changed recently., (*19)

Contributing

Please see CONTRIBUTING for details., (*20)

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities., (*21)

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., (*22)

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium., (*23)

We publish all received postcards on our company website., (*24)

Credits

License

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

The Versions

04/05 2018

dev-master

9999999-dev https://github.com/spatie/url

Parse, build and manipulate URL's

  Sources   Download

MIT

The Requires

 

The Development Requires

url spatie

02/01 2018

1.3.0

1.3.0.0 https://github.com/spatie/url

Parse, build and manipulate URL's

  Sources   Download

MIT

The Requires

 

The Development Requires

url spatie

18/09 2017

1.2.0

1.2.0.0 https://github.com/spatie/url

Parse, build and manipulate URL's

  Sources   Download

MIT

The Requires

 

The Development Requires

url spatie

01/07 2017

1.1.0

1.1.0.0 https://github.com/spatie/url

Parse, build and manipulate URL's

  Sources   Download

MIT

The Requires

 

The Development Requires

url spatie

09/03 2017

1.0.2

1.0.2.0 https://github.com/spatie/url

Parse, build and manipulate URL's

  Sources   Download

MIT

The Requires

 

The Development Requires

url spatie

09/03 2017

dev-analysis-zRoQ9M

dev-analysis-zRoQ9M https://github.com/spatie/url

Parse, build and manipulate URL's

  Sources   Download

MIT

The Requires

 

The Development Requires

url spatie

09/03 2017

dev-analysis-q1Za5w

dev-analysis-q1Za5w https://github.com/spatie/url

Parse, build and manipulate URL's

  Sources   Download

MIT

The Requires

 

The Development Requires

url spatie

14/11 2016

1.0.1

1.0.1.0 https://github.com/spatie/url

Parse, build and manipulate URL's

  Sources   Download

MIT

The Requires

 

The Development Requires

url spatie

07/10 2016

1.0.0

1.0.0.0 https://github.com/spatie/url

Parse, build and manipulate URL's

  Sources   Download

MIT

The Requires

 

The Development Requires

url spatie

26/09 2016

dev-code-review

dev-code-review https://github.com/spatie/url

Parse, build and manipulate URL's

  Sources   Download

MIT

The Requires

 

The Development Requires

url spatie

21/09 2016

0.3.0

0.3.0.0 https://github.com/spatie/url

:package_description

  Sources   Download

MIT

The Requires

 

The Development Requires

url spatie

14/09 2016

0.2.0

0.2.0.0 https://github.com/spatie/url

:package_description

  Sources   Download

MIT

The Requires

 

The Development Requires

url spatie

13/09 2016

0.1.0

0.1.0.0 https://github.com/spatie/url

:package_description

  Sources   Download

MIT

The Requires

 

The Development Requires

url spatie