Documentation for crwlr / url (v2.1)

All Available Url Components

Below, you can see a visualization of all the components that are available to you via a Url object.

https://john:123@subdomain.example.com:8080/foo?bar=baz#anchor

                     domainLabel  domainSuffix
                              ↓     ↓
 _____  ____ ___ _____________________ ____ ____ _______ ______
|https||john|123|subdomain.example.com|8080|/foo|bar=baz|anchor|
 ‾‾‾‾‾  ‾‾‾‾ ‾‾‾ ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ ‾‾‾‾ ‾‾‾‾ ‾‾‾‾‾‾‾ ‾‾‾‾‾‾
   ↑      ↑   ↑     ↑           ↑       ↑    ↑      ↑       ↑
 scheme user  ↑  subdomain   domain    port path  query  fragment
              ↑        ⤷ host ⤶
       |   pass(word)                      |
       |___________________________________|
       |john:123@subdomain.example.com:8080|
       |‾‾‾‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
       |________|         ↑
       |john:123|     authority
        ‾‾‾‾‾‾‾‾
            ↑
        userInfo

When a component is not present in an url (e.g. it doesn't contain user and password) the corresponding properties will return NULL.

Further available component combinations

The following combinations of components aren't really common, but may as well be useful sometimes.

 _______________________   ___________________
|https://www.example.com| |/foo?bar=baz#anchor|
 ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾   ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
            ↑                       ↑
          root                  relative

root

The root as it's called here, consists of the scheme and the authority components.

$url = Url::parse('https://www.example.com:8080/foo?bar=baz');
$root = $url->root();   // => "https://www.example.com:8080"

relative

Complementary to root you can retrieve path, query and fragment via the relative method.

$url = Url::parse('https://www.example.com/foo?bar=baz#anchor');
$relative = $url->relative();   // => "/foo?bar=baz#anchor"