php8.5
Home/ Manual/ whatwg / url/ Uri\WhatWg\Url::getPort

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)
NULL

See Also

  • Uri\WhatWg\Url::withPort
  • Uri\Rfc3986\Uri::getPort

Source: reference/uri/uri/whatwg/url/getport.xml · from the official PHP manual (php/doc-en)