Uri\WhatWg\Url::withFragment
PHP function
Edit on GitHub ✎
(PHP 8 >= 8.5.0)
Modify the fragment component
Description
Uri\WhatWg\Url::withFragment(string|null $fragment): static
Creates a new URL and modifies its fragment component.
Parameters
fragmentNew fragment component.
Return Values
The modified Uri\WhatWg\Url instance.
Errors/Exceptions InvalidUrlException
Examples
Uri\WhatWg\Url::withFragment basic example
php
<?php
$url = new \Uri\WhatWg\Url("https://example.com/#foo");
$url = $url->withFragment("bar");
echo $url->getFragment();
?>The above example will output:
output
barSee Also
Uri\WhatWg\Url::getFragmentUri\Rfc3986\Uri::withFragment