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
fragmentNew 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
barSee Also
Uri\Rfc3986\Uri::getFragmentUri\Rfc3986\Uri::getRawFragmentUri\WhatWg\Url::withFragment