array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ru', ), 'this' => array ( 0 => 'uri-whatwg-url.withusername.php', 1 => 'Uri\\WhatWg\\Url::withUsername', 2 => 'Modify the username component', ), 'up' => array ( 0 => 'class.uri-whatwg-url.php', 1 => 'Uri\\WhatWg\\Url', ), 'prev' => array ( 0 => 'uri-whatwg-url.withscheme.php', 1 => 'Uri\\WhatWg\\Url::withScheme', ), 'next' => array ( 0 => 'enum.uri-uricomparisonmode.php', 1 => 'Uri\\UriComparisonMode', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/uri/uri/whatwg/url/withusername.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>

Uri\WhatWg\Url::withUsername

(PHP 8 >= 8.5.0)

Uri\WhatWg\Url::withUsernameModify the username component

Описание

public Uri\WhatWg\Url::withUsername(?string $username): static

Creates a new URL and modifies its username component.

Список параметров

username
New username component.

Возвращаемые значения

The modified Uri\WhatWg\Url instance.

Ошибки

If the resulting URL is invalid, a Uri\WhatWg\InvalidUrlException is thrown.

Примеры

Пример #1 Uri\WhatWg\Url::withUsername() basic example

<?php
$url
= new \Uri\WhatWg\Url("https://user:password@example.com");
$url = $url->withUsername("usr");

echo
$url->getUsername();
?>

Результат выполнения приведённого примера:

usr

Смотрите также