Uri\WhatWg\Url::withFragment
PHP Manual
PHP Manual»Uri\WhatWg\Url»Uri\WhatWg\Url::withFragment

Uri\WhatWg\Url::withFragment

(PHP 8 >= 8.5.0)

Uri\WhatWg\Url::withFragment — Modifica o componente fragment

Descrição

public function Uri\WhatWg\Url::withFragment(?string $fragment): static

Cria uma nova URL e modifica seu componente 'fragment'.

Parâmetros

fragment

Novo componente 'fragment'.

Valor Retornado

A instância de Uri\WhatWg\Url modificada.

Erros/Exceções

Se o URL resultante for inválido, é lançada uma Uri\WhatWg\InvalidUrlException.

Examples

Exemplo #1 Exemplo básico de Uri\WhatWg\Url::withFragment()

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

echo $url->getFragment();
?>

O exemplo acima produzirá:

bar

Veja também

To Top