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

Uri\WhatWg\Url::withHost

PHP function Edit on GitHub ✎

(PHP 8 >= 8.5.0)

Modify the host component

Description

Uri\WhatWg\Url::withHost(string|null $host): static

Creates a new URL and modifies its host component.

Parameters

host

New host component.

Return Values

The modified Uri\WhatWg\Url instance.

Errors/Exceptions InvalidUrlException

Examples

Uri\WhatWg\Url::withHost basic example

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

echo $url->getAsciiHost();
?>

The above example will output:

output
example.net

See Also

  • Uri\WhatWg\Url::getAsciiHost
  • Uri\WhatWg\Url::getUnicodeHost
  • Uri\Rfc3986\Uri::withHost

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