Uri\WhatWg\Url::getPort
PHP function
Edit on GitHub ✎
(PHP 8 >= 8.5.0)
Retrieve the port component
Description
Uri\WhatWg\Url::getPort(): int|null
Retrieves the port component.
Parameters Parameters
Return Values
Returns the port component as an Integer if the port component exists, null is returned otherwise.
Examples
Uri\WhatWg\Url::getPort basic example
php
<?php
$url = new \Uri\WhatWg\Url("https://example.com:8080");
var_dump($url->getPort());
// 443 is the default port for https, so it is not stored.
$url = new \Uri\WhatWg\Url("https://example.com:443");
var_dump($url->getPort());
?>The above example will output:
output
int(8080)
NULLSee Also
Uri\WhatWg\Url::withPortUri\Rfc3986\Uri::getPort