Uri\Rfc3986\Uri::withHost
(PHP 8 >= 8.5.0)
Uri\Rfc3986\Uri::withHost — Modify the host component
Description
Creates a new URI and modifies its host component.
Parameters
host
New host component.
Return Values
The modified Uri\Rfc3986\Uri instance.
Errors/Exceptions
If the resulting URI is invalid, a Uri\InvalidUriException is thrown.
Examples
Example #1 Uri\Rfc3986\Uri::withHost() basic example
<?php
$uri = new \Uri\Rfc3986\Uri("https://example.com");
$uri = $uri->withHost("example.net");
echo $uri->getHost();
?>The above example will output:
example.net
See Also
- Uri\Rfc3986\Uri::getHost() - Retrieve the normalized host component
- Uri\Rfc3986\Uri::getRawHost() - Retrieve the raw host component
- Uri\WhatWg\Url::withHost() - Modify the host component
来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。
