php8.5
Home/ Manual/ whatwg / url/ Uri\WhatWg\Url::withFragment

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

fragment

New 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
bar

See Also

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

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