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

Uri\WhatWg\Url::withPassword

PHP function Edit on GitHub ✎

(PHP 8 >= 8.5.0)

Modify the password component

Description

Uri\WhatWg\Url::withPassword(string|null $password): static

Creates a new URL and modifies its password component.

Parameters

password

New password component.

Return Values

The modified Uri\WhatWg\Url instance.

Errors/Exceptions InvalidUrlException

Examples

Uri\WhatWg\Url::withPassword basic example

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

echo $url->getPassword();
?>

The above example will output:

output
pass

See Also

  • Uri\WhatWg\Url::getPassword
  • Uri\WhatWg\Url::getUsername
  • Uri\Rfc3986\Uri::withUserInfo

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