(PHP 8 >= 8.5.0)
Uri\Rfc3986\Uri::withFragment — Modify the fragment component
$fragment
Creates a new URI and modifies its fragment component.
fragment
New fragment component.
The modified Uri\Rfc3986\Uri instance.
If the resulting URI is invalid, a Uri\InvalidUriException is thrown.
Example #1 Uri\Rfc3986\Uri::withFragment() basic example
<?php $uri = new \Uri\Rfc3986\Uri("https://example.com/#foo"); $uri = $uri->withFragment("bar"); echo $uri->getFragment();
The above example will output:
bar