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

Uri\WhatWg\Url::withScheme

PHP function Edit on GitHub ✎

(PHP 8 >= 8.5.0)

Modify the scheme component

Description

Uri\WhatWg\Url::withScheme(string $scheme): static

Creates a new URL and modifies its scheme component.

Parameters

scheme

New scheme component.

Return Values

The modified Uri\WhatWg\Url instance.

Errors/Exceptions InvalidUrlException

Examples

Uri\WhatWg\Url::withScheme basic example

php
<?php
$url = new \Uri\WhatWg\Url("https://example.com");
$url = $url->withScheme("http");

echo $url->getScheme();
?>

The above example will output:

output
http

See Also

  • Uri\WhatWg\Url::getScheme
  • Uri\Rfc3986\Uri::withScheme

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