Uri\WhatWg\Url::withUsername
PHP function
Edit on GitHub ✎
(PHP 8 >= 8.5.0)
Modify the username component
Description
Uri\WhatWg\Url::withUsername(string|null $username): static
Creates a new URL and modifies its username component.
Parameters
usernameNew username component.
Return Values
The modified Uri\WhatWg\Url instance.
Errors/Exceptions InvalidUrlException
Examples
Uri\WhatWg\Url::withUsername basic example
php
<?php
$url = new \Uri\WhatWg\Url("https://user:password@example.com");
$url = $url->withUsername("usr");
echo $url->getUsername();
?>The above example will output:
output
usrSee Also
Uri\WhatWg\Url::getUsernameUri\WhatWg\Url::getPasswordUri\Rfc3986\Uri::withUserInfo