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
hostNew 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.netSee Also
Uri\WhatWg\Url::getAsciiHostUri\WhatWg\Url::getUnicodeHostUri\Rfc3986\Uri::withHost