Download the PHP package wa72/url without Composer
On this page you can find all versions of the php package wa72/url. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package url
Short Description Class for handling and manipulating URLs
License MIT
Homepage http://github.com/wasinger/url
Informations about the package url
url
PHP class for handling and manipulating URLs. It's a pragmatic one-class lib that is completely framework independent.
- Parse URL strings to objects
- add and modify query parameters
- set and modify any part of the url
- test for equality of URLs with query parameters in a PHP-fashioned way
- supports protocol-relative urls
-
convert absolute, host-relative and protocol-relative urls to relative and vice versa
- New in version 0.7 (2018/07/25): optional compatibility with
Psr\Http\Message\UriInterface
(PSR-7), see below
Installation
This package is listed on Packagist.
Features and Usage
Parse a URL to an object
Easily modify and add query parameters
Compare URLs with query strings the PHP way
While in general a URL may have multiple query parameters with the same name
(e.g. ?a=value1&a=value2&a=value3
) and there are web applications that convert
those parameters into an array, this is not the PHP way of dealing with query parameters:
In PHP, the last parameter with the same name always wins, so the
above query string is equal to only ?a=value3
.
Similarly, while in general the order of query parameters in the query string may
be significant to a web application, it is not in PHP: ?a=1&b=2
is equivalent
to ?b=2&a=1
for a PHP application.
Url
deals with query strings in URLs like PHP does, so the URLs in the following
example are to be considered equal:
Make relative URL absolute
A given URL that has
- no scheme (protocol-relative URL)
- no scheme and no host (host-relative URL)
- no scheme, no host, and a relative path (relative URL)
can be turned into an absolute URL by a given base URL:
Output protocol-relative and host-relative URLs
If you want to omit the scheme, or scheme and host, when outputting the URL
you can pass Url::WRITE_FLAG_OMIT_SCHEME
and with Url::WRITE_FLAG_OMIT_HOST
to the write()
-method:
Compatibility with Psr\Http\Message\UriInterface
(PSR-7)
- class
Url
now has all methods defined in this interface but does not officially implement it. - new wrapper class
Psr7Uri
that implementsUriInterface
- methods for converting between
Url
andPsr7Uri
Class Url
does not implement the PSR Interface by itself for two reasons:
- To not introduce a new dependency on the PSR interface. The dependency is only "suggested" in composer json.
- Because the PSR interface is designed to be immutable,
while
Url
is not.
To use this feature, you need to composer require psr/http-message
.
More documentation to come
Meanwhile, have a look at the source code, there are lots of comments in it.
(c) Christoph Singer 2018. Licensed under the MIT license.