Skip to content
/ url Public

Makes the algorithms and APIs defined by URL Standard (replaces RFC 3986 and RFC 3987) available on PHP. / URL Standard (RFC 3986、RFC 3987 を置き換える Web 標準仕様) で定義されているアルゴリズム、および API を PHP から利用できるようにします。

License

Notifications You must be signed in to change notification settings

esperecyan/url

Repository files navigation

English / 日本語

URL Standard

Makes the algorithms and APIs defined by URL Standard available on PHP.

Description

URL Standard is the Web standard specification that replaces the previous standards RFC 3986 and RFC 3987.

The specification defines URL interface and URLSearchPrams interface as API. This library allows you to use esperecyan\url\URL class as URL interface and esperecyan\url\URLSearchParams class as URLSearchPrams interface. The documents on MDN may be easy to understand by way of explanation of the interfaces https://developer.mozilla.org/docs/Web/API/URL https://developer.mozilla.org/docs/Web/API/URLSearchParams .

This library allows you to use the algorithms defined by URL Standard. For details, see The correspondence table of the algorithms.

Example

<?php
require_once 'vendor/autoload.php';

use esperecyan\url\URL;

$url = new URL('http://url.test/foobar?name=value');
var_dump($url->protocol, $url->pathname, $url->searchParams->get('name'));

The above example will output:

string(5) "http:"
string(7) "/foobar"
string(5) "value"

Requirement

  • PHP 5.4, or 7.2 or later (PHP 5.4 and 7.2 are deprecated)
    • SPL Types PECL library is not supported

Install

composer require esperecyan/url

For help with installation of Composer, see Composer documentation.

Contribution

  1. Fork it ( https://github.com/esperecyan/url )
  2. Create your feature branch git checkout -b my-new-feature
  3. Commit your changes git commit -am 'Add some feature'
  4. Push to the branch git push origin my-new-feature
  5. Create new Pull Request

Or

Create new Issue

If you find any mistakes of English in the README or Doc comments or any flaws in tests, please report by such as above means. I also welcome translations of README too.

Acknowledgement

I use the code from コードポイントから UTF-8 の文字を生成する - Qiita and UTF-8 の文字からコードポイントを求める - Qiita in implementing URLencoding class.

I use URL Standard (Japanese translation) as reference in creating this library.

HADAA helped me translate README to English.

Semantic Versioning

This library uses Semantic Versioning. The classes, methods, constants, and properties in the documentation of the library are the public API.

Licence

This library is licensed under the Mozilla Public License Version 2.0 (MPL-2.0).

The correspondence table of the algorithms

1. Infrastructure
percent encode esperecyan\url\lib\Infrastructure::percentEncode()
percent decode esperecyan\url\lib\Infrastructure::percentDecode()
C0 control percent-encode set esperecyan\url\lib\Infrastructure::C0_CONTROL_PERCENT_ENCODE_SET
path percent-encode set esperecyan\url\lib\Infrastructure::PATH_PERCENT_ENCODE_SET
userinfo percent-encode set esperecyan\url\lib\Infrastructure::USERINFO_PERCENT_ENCODE_SET
utf-8 percent encode esperecyan\url\lib\Infrastructure::utf8PercentEncode()
3. Hosts (domains and IP addresses)
domain
opaque host
empty host
A valid utf-8 string
IPv4 address An integer or float in the range 0 to 0xFFFFFFFF
IPv6 address An array with 8 elements of an integer in the range 0 to 0xFFFF
forbidden host code point esperecyan\url\lib\HostProcessing::FORBIDDEN_HOST_CODE_POINTS
domain to ASCII esperecyan\url\lib\HostProcessing::domainToASCII()
domain to Unicode esperecyan\url\lib\HostProcessing::domainToUnicode()
valid domain esperecyan\url\lib\HostProcessing::isValidDomain()
host parser esperecyan\url\lib\HostProcessing::parseHost()
IPv4 number parser esperecyan\url\lib\HostProcessing::parseIPv4Number()
IPv4 parser esperecyan\url\lib\HostProcessing::parseIPv4()
IPv6 parser esperecyan\url\lib\HostProcessing::parseIPv6()
opaque-host parser esperecyan\url\lib\HostProcessing::parseOpaqueHost()
host serializer esperecyan\url\lib\HostProcessing::serializeHost()
IPv4 serializer esperecyan\url\lib\HostProcessing::serializeIPv4()
IPv6 serializer esperecyan\url\lib\HostProcessing::serializeIPv6()
4. URLs
URL An instance of esperecyan\url\lib\URL class
scheme esperecyan\url\lib\URL->scheme
username esperecyan\url\lib\URL->username
password esperecyan\url\lib\URL->password
host esperecyan\url\lib\URL->host
port esperecyan\url\lib\URL->port
path esperecyan\url\lib\URL->path
query esperecyan\url\lib\URL->query
fragment esperecyan\url\lib\URL->fragment
cannot-be-a-base-URL flag esperecyan\url\lib\URL->cannotBeABaseURLFlag
object esperecyan\url\lib\URL->object
special scheme esperecyan\url\lib\URL::$specialSchemes
is special esperecyan\url\lib\URL->isSpecial()
includes credentials esperecyan\url\lib\URL->isIncludingCredentials()
cannot have a username/password/port esperecyan\url\lib\URL->cannotHaveUsernamePasswordPort()
Windows drive letter esperecyan\url\lib\URL::WINDOWS_DRIVE_LETTER
normalized Windows drive letter esperecyan\url\lib\URL::NORMALIZED_WINDOWS_DRIVE_LETTER
starts with a Windows drive letter esperecyan\url\lib\URL::stringStartsWithWindowsDriveLetter()
shorten a path esperecyan\url\lib\URL->shortenPath()
single-dot path segment esperecyan\url\lib\URL::SINGLE_DOT_PATH_SEGMENT
double-dot path segment esperecyan\url\lib\URL::DOUBLE_DOT_PATH_SEGMENT
URL code points esperecyan\url\lib\URL::URL_CODE_POINTS
URL parser esperecyan\url\lib\URL::parseURL()
basic URL parser esperecyan\url\lib\URL::parseBasicURL()
set the username esperecyan\url\lib\URL->setUsername()
set the password esperecyan\url\lib\URL->setPassword()
URL serializer esperecyan\url\lib\URL->serializeURL()
origin esperecyan\url\lib\URL->getOrigin()
5. application/x-www-form-urlencoded
application/x-www-form-urlencoded parser esperecyan\url\lib\URLencoding::parseURLencoded()
application/x-www-form-urlencoded byte serializer esperecyan\url\lib\URLencoding::serializeURLencodedByte()
application/x-www-form-urlencoded serializer esperecyan\url\lib\URLencoding::serializeURLencoded()
application/x-www-form-urlencoded string parser esperecyan\url\lib\URLencoding::parseURLencodedString()
name-value or name-value-type tuples An array of two-element or three-element arrays with the first element the name, the second the value, and the third the type. The value is an array with the value for name key as the name

About

Makes the algorithms and APIs defined by URL Standard (replaces RFC 3986 and RFC 3987) available on PHP. / URL Standard (RFC 3986、RFC 3987 を置き換える Web 標準仕様) で定義されているアルゴリズム、および API を PHP から利用できるようにします。

Topics

Resources

License

Stars

Watchers

Forks

Languages