Uri\WhatWg\Url::withPort
(PHP 8 >= 8.5.0)
Uri\WhatWg\Url::withPort — Modify the port component
Description
Creates a new URL and modifies its port component.
Parameters
port
New port component.
Return Values
The modified Uri\WhatWg\Url instance.
Errors/Exceptions
If the resulting URL is invalid, a Uri\WhatWg\InvalidUrlException is thrown.
Examples
Example #1 Uri\WhatWg\Url::withPort() basic example
<?php
$url = new \Uri\WhatWg\Url("https://example.com:8080");
// 443 is the default port for https, so it is not stored.
$url = $url->withPort(443);
var_dump($url->getPort());
$url = $url->withPort(8443);
var_dump($url->getPort());
?>The above example will output:
NULL int(8443)
See Also
- Uri\WhatWg\Url::getPort() - Retrieve the port component
- Uri\Rfc3986\Uri::withPort() - Modify the port component
来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。
