php8.5
Home/ Manual/ rfc3986 / uri/ Uri\Rfc3986\Uri::withScheme

Uri\Rfc3986\Uri::withScheme

PHP function Edit on GitHub ✎

(PHP 8 >= 8.5.0)

Modify the scheme component

Description

Uri\Rfc3986\Uri::withScheme(string|null $scheme): static

Creates a new URI and modifies its scheme component.

Parameters

scheme

New scheme component.

Return Values

The modified Uri\Rfc3986\Uri instance.

Errors/Exceptions InvalidUriException

Examples

Uri\Rfc3986\Uri::withScheme basic example

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

echo $uri->getScheme();
?>

The above example will output:

output
http

See Also

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

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