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

Uri\Rfc3986\Uri::withFragment

PHP function Edit on GitHub ✎

(PHP 8 >= 8.5.0)

Modify the fragment component

Description

Uri\Rfc3986\Uri::withFragment(string|null $fragment): static

Creates a new URI and modifies its fragment component.

Parameters

fragment

New fragment component.

Return Values

The modified Uri\Rfc3986\Uri instance.

Errors/Exceptions InvalidUriException

Examples

Uri\Rfc3986\Uri::withFragment basic example

php
<?php
$uri = new \Uri\Rfc3986\Uri("https://example.com/#foo");
$uri = $uri->withFragment("bar");

echo $uri->getFragment();
?>

The above example will output:

output
bar

See Also

  • Uri\Rfc3986\Uri::getFragment
  • Uri\Rfc3986\Uri::getRawFragment
  • Uri\WhatWg\Url::withFragment

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