« Uri\WhatWg\Url::withFragment
Uri\WhatWg\Url::withPassword »

Uri\WhatWg\Url::withHost

(PHP 8 >= 8.5.0)

Uri\WhatWg\Url::withHost — ホストコンポーネントを変更する

説明

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

新しい URL を作成し、そのホストコンポーネントを変更します。

パラメータ

host

新しいホストコンポーネント。

戻り値

変更された Uri\WhatWg\Url インスタンス。

エラー / 例外

結果の URL が不正な場合、Uri\WhatWg\InvalidUrlException がスローされます。

例

例1 Uri\WhatWg\Url::withHost() の基本的な例

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

echo $url->getAsciiHost();
?>

上の例の出力は以下となります。

example.net

参考

関連キーワード:
WhatWg   ホスト   コンポーネント   withHost   example   host   getAsciiHost   withFragment   withPassword   static   インスタンス   不正   InvalidUrlException   基本的   https   参考   getUnicodeHost   Unicode
関連する関数・ページ:
uri-whatwg-url.getasciihost   uri-whatwg-url.getunicodehost   uri-rfc3986-uri.withhost   uri-whatwg-url.withpassword   class.uri-whatwg-url   uri-rfc3986-uri.gethost