bermudaphp / url
v1.0
2023-03-03 13:09 UTC
Requires
- php: ^8.1
- bermudaphp/arrayable: ^1.0
This package is auto-updated.
Last update: 2024-11-14 23:17:12 UTC
README
composer require bermudaphp/url
Usage
$url = Url::parse('http://username:password@hostname:9090/path?arg=value#anchor'); ^ Bermuda\Url\Url {#231 ▼ -segments: array:8 [▼ "scheme" => "http" "host" => "hostname" "port" => 9090 "user" => "username" "pass" => "password" "path" => "/path" "query" => "arg=value" "fragment" => "anchor" ] } $url->without('fragment', 'path')->toString(); // "http://username:password@hostname:9090/?arg=value" $currentUrl = Url::fromGlobals()->toString(); // https://github.com/bermudaphp/url $currentUrl = $currentUrl->withHost('new-hostname.com'); $currentUrl->host; // 'new-hostname.com' $currentUrl->toString(); // 'https://new-hostname.com/bermudaphp/url' $currentUrl->toArray(); ^ array:1 [▼ "segments" => array:3 [▼ "scheme" => "https" "host" => "new-hostname.com" "path" => "/bermudaphp/url" ] ] Url::build(['scheme' => 'https', 'host' => 'github.com', 'path' => 'bermudaphp/url']); // "https://github.com/bermudaphp/url"