php8.5
Home/ Manual/ whatwg / url/ Uri\WhatWg\Url::resolve

Uri\WhatWg\Url::resolve

PHP function Edit on GitHub ✎

(PHP 8 >= 8.5.0)

Resolve a URL with the current object as the base URL

Description

Uri\WhatWg\Url::resolve(string $uri, array $softErrors = null): static

Resolves a valid URL string - which may potentially be a relative-URL string - with the current object as the base URL.

Parameters

uri

A valid URL string (e.g. /foo or (e.g. https://example.com/foo) to apply on the current object.

softErrors

An Array to pass a list of Uri\WhatWg\UrlValidationError instances by reference to provide extended information about the soft errors triggered during reference resolution.

Return Values

A new Uri\WhatWg\Url instance.

Errors/Exceptions InvalidUrlException

Examples

Uri\WhatWg\Url::resolve basic example

php
<?php
$url = new \Uri\WhatWg\Url("https://example.com");
$url = $url->resolve("/foo");

echo $url->toAsciiString();
?>

The above example will output:

output
https://example.com/foo

See Also

  • Uri\WhatWg\Url::__construct
  • Uri\WhatWg\Url::parse
  • Uri\Rfc3986\Uri::resolve

Source: reference/uri/uri/whatwg/url/resolve.xml · from the official PHP manual (php/doc-en)