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

Uri\WhatWg\Url::getUsername

PHP function Edit on GitHub ✎

(PHP 8 >= 8.5.0)

Retrieve the username component

Description

Uri\WhatWg\Url::getUsername(): string|null

Retrieves the username component.

Parameters Parameters

Return Values

Returns the username component as a String if the username component exists, null is returned otherwise.

Examples

Uri\WhatWg\Url::getUsername basic example

php
<?php
$url = new \Uri\WhatWg\Url("https://username:password@example.com");

echo $url->getUsername();
?>

The above example will output:

output
username

See Also

  • Uri\WhatWg\Url::withUsername
  • Uri\Rfc3986\Uri::getRawUsername
  • Uri\Rfc3986\Uri::getUsername

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