PHPackages                             alxndr-w/kit-urlparser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. alxndr-w/kit-urlparser

ActiveLibrary[HTTP &amp; Networking](/categories/http)

alxndr-w/kit-urlparser
======================

RFC 3986 compliant url parsing library with PSR-7 Uri component

v2.2.1(10mo ago)0513↑350%MITPHPPHP &gt;=8.1.0CI failing

Since Oct 21Pushed 9mo agoCompare

[ Source](https://github.com/alxndr-w/Kit-UrlParser)[ Packagist](https://packagist.org/packages/alxndr-w/kit-urlparser)[ Docs](http://kit.riimu.net)[ RSS](/packages/alxndr-w-kit-urlparser/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (14)Used By (0)

RFC 3986 URL Parser
===================

[](#rfc-3986-url-parser)

> This is a WIP-Fork of  fixing [Riimu#7](https://github.com/Riimu/Kit-UrlParser/pull/7) and to make it available via composer.

*UrlParser* is PHP library that provides a [RFC 3986](https://tools.ietf.org/html/rfc3986)compliant URL parser and a [PSR-7](http://www.php-fig.org/psr/psr-7/) compatible URI component. The purpose of this library is to provide a parser that accurately implements the RFC specification unlike the built in function `parse_url()`, which differs from the specification in some subtle ways.

This library has two main purposes. The first to provide information from the parsed URLs. To achieve this, the library implements the standard URI handling interface from the PSR-7 and also provides additional methods that make it easier to retrieve commonly used information from the URLs. The second purpose is to also permit the modification of said URLs using the interface from the PSR-7 standard in addition to few extra methods that make some tasks more straightforward.

While this library is mainly intended for parsing URLs, the parsing is simply based on the generic URI syntax. Thus, it is possible to use this library to validate and parse any other types of URIs against the generic syntax. The library does not perform any scheme specific validation for the URLs.

In addition to the default RFC 3986 compliant mode, the library also offers options that allow parsing of URLs that contain UTF-8 characters in different components of the URL while converting them to the appropriate percent encoded and IDN ascii formats.

The API documentation is available at:

[![CI](https://camo.githubusercontent.com/225ac2bd9f2a464ffd590b0ea1897dc54e44b8f362ba0648551f86fd7a6add58/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f5269696d752f4b69742d55726c5061727365722f43492f6d61696e3f7374796c653d666c61742d737175617265)](https://github.com/Riimu/Kit-UrlParser/actions)[![Scrutinizer](https://camo.githubusercontent.com/af3b313b43adbceffa76f174ecd0de078800f741316cf641f7062708be316564/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f5269696d752f4b69742d55726c5061727365722f6d61696e3f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Riimu/Kit-UrlParser/)[![codecov](https://camo.githubusercontent.com/094ff129db281608a7e6bedc89169828a509bd9fa2cb5f444d00132245923c46/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f5269696d752f4b69742d55726c5061727365722f6d61696e3f7374796c653d666c61742d737175617265)](https://codecov.io/gh/Riimu/Kit-UrlParser)[![Packagist](https://camo.githubusercontent.com/f86af48a1c2d6403156c739625907dc206f7e2465c5c3b8445f079114d77009c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7269696d752f6b69742d75726c7061727365722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/riimu/kit-urlparser)

Requirements
------------

[](#requirements)

- The minimum supported PHP version is 5.6
- The library depends on the following external PHP libraries:
    - [psr/http-message](https://packagist.org/packages/psr/http-message) (`^1.0`)
- The library depends on the following PHP Extensions
    - [`intl`](http://php.net/manual/en/book.intl.php) (only required IDN support)

Installation
------------

[](#installation)

### Installation with Composer

[](#installation-with-composer)

The easiest way to install this library is to use Composer to handle your dependencies. In order to install this library via Composer, simply follow these two steps:

1. Acquire the `composer.phar` by running the Composer [Command-line installation](https://getcomposer.org/download/)in your project root.
2. Once you have run the installation script, you should have the `composer.phar`file in you project root and you can run the following command:

    ```
    php composer.phar require "riimu/kit-urlparser:^2.1"

    ```

After installing this library via Composer, you can load the library by including the `vendor/autoload.php` file that was generated by Composer during the installation.

### Adding the library as a dependency

[](#adding-the-library-as-a-dependency)

If you are already familiar with how to use Composer, you may alternatively add the library as a dependency by adding the following `composer.json` file to your project and running the `composer install` command:

```
{
    "require": {
        "riimu/kit-urlparser": "^2.1"
    }
}
```

### Manual installation

[](#manual-installation)

If you do not wish to use Composer to load the library, you may also download the library manually by downloading the [latest release](https://github.com/Riimu/Kit-UrlParser/releases/latest)and extracting the `src` folder to your project. You may then include the provided `src/autoload.php` file to load the library classes.

Please note that using Composer will also automatically download the other required PHP libraries. If you install this library manually, you will also need to make those other required libraries available.

Usage
-----

[](#usage)

Using this library is relatively straightforward. The library provides a URL parsing class `UriParser` and an immutable value object class `Uri` that represents the URL. To parse an URL, you could simply provide the URL as a string to the `parse()` method in `UriParser` which returns an instance of `Uri`that has been generated from the parsed URL.

For example:

```
