Skip to content

Url

Properties

originalUrl

public null|string $originalUrl

scheme

private string $scheme

username

public ?string $username

password

private ?string $password

host

private string $host

port

private ?int $port

path

private string $path

originalPath

Original path with no sanitization to ending slash.

private string|null $originalPath

params

private array $params

fragment

private string $fragment

Methods

__construct

public __construct(string $uri = ''): mixed

Parameters:

Parameter Type Description
$uri string

Throws:


parse

public parse(?string $url = null, bool $originalPath = false): self

Parameters:

Parameter Type Description
$url ?string
$originalPath bool

Throws:


isSecure

Check if url is using a secure protocol like https.

public isSecure(): bool

isRelative

Checks if url is relative.

public isRelative(): bool

withUsername

Set the username of the url

public withUsername(string $username): static

Parameters:

Parameter Type Description
$username string

withPassword

Set the url password

public withPassword(string $password): static

Parameters:

Parameter Type Description
$password string

withPath

Set the url path

public withPath(string $path): static

Parameters:

Parameter Type Description
$path string

mergeParams

Merge parameters array

public mergeParams(array $params): static

Parameters:

Parameter Type Description
$params array

withParams

Set the url params

public withParams(array $params): static

Parameters:

Parameter Type Description
$params array

withQueryString

Set raw query-string parameters as string

public withQueryString(string $queryString): static

Parameters:

Parameter Type Description
$queryString string

getQueryString

Get query-string params as string

public getQueryString(): string

getFragment

Get fragment from url (everything after #)

public getFragment(): string

indexOf

Get position of value.

public indexOf(string $value): int

Returns -1 on failure.

Parameters:

Parameter Type Description
$value string

contains

Check if url contains value.

public contains(string $value): bool

Parameters:

Parameter Type Description
$value string

hasParam

Check if url contains parameter/query string.

public hasParam(string $name): bool

Parameters:

Parameter Type Description
$name string

removeParams

Removes multiple parameters from the query-string

public removeParams(int[]|string[] $names): static

Parameters:

Parameter Type Description
$names int[]|string[]

removeParam

Removes parameter from the query-string

public removeParam(string $name): static

Parameters:

Parameter Type Description
$name string

getParam

Get parameter by name.

public getParam(string $name, ?string $defaultValue = null): ?string

Returns parameter value or default value.

Parameters:

Parameter Type Description
$name string
$defaultValue ?string

parseUrl

UTF-8 aware parse_url() replacement.

public parseUrl(string $url, int $component = -1): array

Parameters:

Parameter Type Description
$url string
$component int

Throws:


arrayToParams

Convert array to query-string params.

public static arrayToParams(array $getParams = [], bool $includeEmpty = true): string
  • This method is static.

Parameters:

Parameter Type Description
$getParams array
$includeEmpty bool

getRelativeUrl

Returns the relative url

public getRelativeUrl(bool $includeParams = true): string

Parameters:

Parameter Type Description
$includeParams bool

getAbsoluteUrl

Returns the absolute url

public getAbsoluteUrl(bool $includeParams = true): string

Parameters:

Parameter Type Description
$includeParams bool

jsonSerialize

Specify data which should be serialized to JSON.

public jsonSerialize(): string

Return Value:

Data which can be serialized by json_encode, which is a value of any type other than a resource.

See Also:

  • http://php.net/manual/en/jsonserializable.jsonserialize.php -

__toString

public __toString(): string


Automatically generated on 2025-10-13