Uri\WhatWg\Url::withHost
PHP Manual
PHP Manual»Uri\WhatWg\Url»Uri\WhatWg\Url::withHost

Uri\WhatWg\Url::withHost

(PHP 8 >= 8.5.0)

Uri\WhatWg\Url::withHostModify the host component

Опис

public function Uri\WhatWg\Url::withHost(?string $host): static

Creates a new URL and modifies its host component.

Параметри

host
New host component.

Значення, що повертаються

The modified Uri\WhatWg\Url instance.

Помилки/виключення

If the resulting URL is invalid, a Uri\WhatWg\InvalidUrlException is thrown.

Приклади

Приклад #1 Uri\WhatWg\Url::withHost() basic example

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

echo $url->getAsciiHost();
?>

Поданий вище приклад виведе:

example.net

Прогляньте також

To Top